Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi everyone,
I have been struggling for quite a while on following calculation:
I have a dataset for which a row is generated for every ID on every day of its lifecycle.
As you can see below for ID = 2 its lifecycle stopped at 03/01/2021 so no longer appears onwards.
ID | Date | Revenue |
1 | 1/01/2021 | 0 |
2 | 1/01/2021 | 0 |
3 | 1/01/2021 | 0 |
1 | 2/01/2021 | 5 |
2 | 2/01/2021 | 0 |
3 | 2/01/2021 | 10 |
1 | 3/01/2021 | 10 |
2 | 3/01/2021 | 5 |
3 | 3/01/2021 | 10 |
1 | 4/01/2021 | 20 |
3 | 4/01/2021 | 30 |
1 | 5/01/2021 | 25 |
I want to able to sum the revenue (actuals) for the lastest available date taking into account the dates selected in slicer from my datetable (1-* with my fact table here above).
Slicer selection : 02/01/2021 and 04/01/2021
Expected result: 02/01/2021 = 5 + 0 + 10 = 15
04/01/2021 = 20 + 5 (latest available value for ID =2 on 03/01/2021) + 30 = 55
Current result: 50 , so it does not take into account the value on 03/01/2020 (5)
With my current formula (see below) I am able to calculate this on row level in my matrix but the total is 50 instead of 55.
I think I need something with Sumx, but I tried and it still doesn't work.
Can anyone help me out with this?
Thanks!!
Solved! Go to Solution.
Hi,
One way to do this is like below (mind its using an unrelated date table).
SumLatestVal =
VAR _selDate = SELECTEDVALUE(DimDate[Date].[Date])
VAR _TblMaxDate =
CALCULATETABLE(
ADDCOLUMNS(
SUMMARIZE('Table',[ID],"MD", MAX([Date])),
"R", LOOKUPVALUE('Table'[Revenue],'Table'[ID],[ID],'Table'[Date].[Date],[MD]))
, FILTER('Table',[Date].[Date] <= _selDate))
RETURN
SUMX(_TblMaxDate,[R])
btw: I also added a debug measure. Pls see below:
File is attached. Enjoy!
Kind regards,
Steve.
Proud to be a Super User!
Awesome Keyboard Shortcusts in Power BI, thumbs up if you like the article
My Community Blog Articles (check them out!)
My Blog - Power M code to automatically detect column types -
How to create test data using DAX!
Hi,
One way to do this is like below (mind its using an unrelated date table).
SumLatestVal =
VAR _selDate = SELECTEDVALUE(DimDate[Date].[Date])
VAR _TblMaxDate =
CALCULATETABLE(
ADDCOLUMNS(
SUMMARIZE('Table',[ID],"MD", MAX([Date])),
"R", LOOKUPVALUE('Table'[Revenue],'Table'[ID],[ID],'Table'[Date].[Date],[MD]))
, FILTER('Table',[Date].[Date] <= _selDate))
RETURN
SUMX(_TblMaxDate,[R])
btw: I also added a debug measure. Pls see below:
File is attached. Enjoy!
Kind regards,
Steve.
Proud to be a Super User!
Awesome Keyboard Shortcusts in Power BI, thumbs up if you like the article
My Community Blog Articles (check them out!)
My Blog - Power M code to automatically detect column types -
How to create test data using DAX!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
47 | |
26 | |
19 | |
14 | |
10 |
User | Count |
---|---|
58 | |
50 | |
44 | |
19 | |
18 |