I am trying to create a measure that will sum invoices totals for all assets but exclude assets whose contracts have expired. The tables look something like this:
Service Data:
Invoice Amount
Asset Key
Invoice Date
Asset Data:
Asset Key
Contract Start Date
Contract End Date
I am also using a date table that is attached to a slicer on the main page of my dashboard. I would like to be able to select a date range on the slicer and have it limit which assets' invoices in includes in the total in respect to the date range selected on the slicer.
Here is what I was attempting so far:
NewISA =
var enddate = MIN(F_Service_Invoice_Summary[Invoice_Date])
Return
IF(
enddate <= F_Asset[End_Date],
SUM(F_Service_Invoice_Summary[Invoice_Segment_Amount]),
0)
Assuming you have a relationship between the ServiceData and AssetData on the AssetKey field and that you have a relationship between your DateTable and ServiceData table on the InvoiceDate field, the following formula should work:
Total Invoiced Active Contracts =
CALCULATE (
SUM ( ServiceData[Invoice Amount] ),
FILTER (
AssetData,
AssetData[Contract Start Date] <= MIN ( DateTable[Date] )
&& AssetData[Contract EndDate] > MAX ( DateTable[Date] )
)
)
We can use MIN(datetable[date]) and MAX(datetable[date]) to determine the interval that is filtered in the datetable to only select contracts that are active during the whole period. Please keep in mind that if you do not select an interval, the formula will only return contracts that started before the first date in your datetable and end after the last date in your datetable.
Related
I have a custom Measure in my excel data model so I can calculate Grand Average in a pivot table...
MyMeasure:=VAR T1 =
SUMMARIZE(HC_Data,HC_Data[data date (Month)], "Total HC", [Count of NAME]) RETURN
IF(HASONEVALUE(HC_Data[data date (Month)]), SUM(HC_Data[HC count]), AVERAGEX( T1, [Total HC]))
now, at first sight, this works wonders! BUT, it doesn't take into accounts months with 0's since the source data wouldn't have a record if there is a 0 in the pivot table.
The pivot table will show a 0 since the columns months are based on a full calendar, and pivot set to show 0 when there is no record. so what i need is a way that the custom Measure accounts for 0's.. is this possible?
Create a new table comprising a unique list of entries from the data date (Month) column and create a relationship between this new table and HC_Data. You can then amend your measure to:
MyMeasure:=VAR T1 =
SUMMARIZE( Months, Months[Month], "Total HC",[Count of NAME] )
RETURN
IF(
HASONEVALUE( HC_Data[data date (Month)] ),
SUM( HC_Data[HC count] ),
AVERAGEX( T1, [Total HC] )
)
I have assumed that the new table is called Months and comprises a single column called Month.
Excel
I'm creating a pivot table and need a column to describe 'average number of orders' made by customers each year.
I have:
Order date
Customer ID
Year
I'm thinking calculated feild, and using COUNT(Order date) to determine number of orders. But I need to be able to use that to get the average number of orders for each customer.
Any help would be appreciated.
Date set example:
Customer ID Order date
Xh015046 12/04/2016
X7615777 03/06/2016
X10062024 20/04/2017
X7615777 25/06/2016
X7615777 05/01/2017
Xh015046 15/04/2017
X10062024 09/07/2018
X7615777 10/07/2018
Xh015046 11/07/2018
X10062024 12/07/2018
Pivot table I want:
Year Average Number of orders per customer
2016 1.5
2017 1
2018 1.333333333
Within the Data Model (Power Pivot), create a new measure:
AverageOrders :=
VAR MyTable =
SUMMARIZE (
Table1,
[Customer ID],
"Order Count", CALCULATE ( COUNTROWS ( Table1 ) )
)
RETURN
AVERAGEX ( MyTable, [Order Count] )
Amend the table (Table1) and column (Customer ID) names in the above as required.
Then create a Pivot Table within the worksheet with Year in the Rows section and the above measure AverageOrders in the Values section.
My Data is in weekly buckets. I want to split the number into a monthly number but, since there is an overlap in days falling in both the months, I want a weighted average of the data in terms of days that fall in each of the months. For example:
Now, in the above picture, I want to split that 200 (5/7*200 in Jan, 2/7 in Feb). How can I do that using Excel/ Power Pivot/ Dax Functions? Any help here is much appreciated.
Thank you!
Assuming your fact table looks something like below. Values are associated with the starting date of the week it occurred.
Although it may actually be a more granular data, having multiple rows for each week with additional attributes (such as identifiers of a person, a store, depending on the business), what being shown below will work the same.
What we need to do first is to create a date table. We can do that in "Design" tab, by clicking "Date Table", then "New".
In this date table, we need to add a column for starting date of the week which the date of each row is in. Set the cursor to "Add Column" area, and input following formula. Then rename this column to "Week Start Date".
= [Date] - [Day Of Week Number] + 1
Now, we can define the measure to calculate the number allocated to each month with following formula. What this measure is doing is:
Iterating over each row of the fact table
Count the number of days for the week visible in the filter context
Add the value portion for the visible days
Value Allocation := SUMX (
MyData,
VAR WeekStartDate = MyData[Week]
VAR NumDaysInSelection = COUNTROWS (
FILTER (
'Calendar',
'Calendar'[Week Start Date] = WeekStartDate
)
)
VAR AllocationRate = DIVIDE ( NumDaysInSelection, 7 )
RETURN AllocationRate * MyData[Value]
)
Result in the pivot table will be looking like this.
I am pretty new in wokrin with data models within Excel, especially in Dax formulas.
I have the following two tables in the data model.
Table_HS:
Product Code - User
Table_IS:
Product Code - Work Order - Date Created - Date Started
Now I want to get an Pivot table with the Product Code (Tabel_HS) and I want to know, how many Work Orders were created (Date Created) this week, and how many were started this week.
How would you manage that?
Sure, I can add the Tabele_IS with =WEEKNUM the week number. But how can I filter the pivot automatically to the current week or the current and the last week?
I don't want to filter every week the specific week number.
Best Regards
Joshua
Create two measures:
Work Orders Created This Week:=
VAR WeekCommencing = TODAY() - WEEKDAY(TODAY(),3)
VAR WeekEnding = WeekCommencing + 6
RETURN
CALCULATE (
DISTINCTCOUNT ( Table_IS[Work Order] ),
Table_IS[Date Created] >= WeekCommencing && Table_IS[Date Created] <= WeekEnding
)
and
Work Orders Started This Week:=
VAR WeekCommencing = TODAY() - WEEKDAY(TODAY(),3)
VAR WeekEnding = WeekCommencing + 6
RETURN
CALCULATE (
DISTINCTCOUNT ( Table_IS[Work Order] ),
Table_IS[Date Started] >= WeekCommencing && Table_IS[Date Started] <= WeekEnding
)
When displaying prior month sales, I noticed that items with no sales in current month are missing in the Pivot Table output of the data model. However, the grand total sales includes sales of those missing items.
I created a small data model to replicate the issue: 2 tables (1 sales table and 1 calendar table) and it has 1 single DAX formula:
Previous Month Sales:=CALCULATE(sum([Sales]),PREVIOUSMONTH(Sales[Date]))
In the output table, I would have expected 1 more item row for Potatoes, with 0 sales in current month and 31 in previous month.
Is there a way to force-show Potatoes item in the pivot table above when selecting date 24/03/2019? Can this be achieved with DAX formulas?
You need to use the Date field from your Calendar (Date) table, for Time Intelligence to work as you intend:
So change your Previous Month Sales measure to:
Sales Previous Month:=CALCULATE (
SUM ( Sales[Sales] ),
PREVIOUSMONTH ( Calendar[Date] )
)
I'd also recommend creating an Explicit Measure for Sales:
Sales Total:=SUM ( Sales[Sales] )
Now you can recreate your pivot output, using Date field(s) from Calendar in your slicer / filter, and you should get the output you require: