March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi
I need to create the measure that calculate the sum of last date in the selected date range for every unique subcategory
The example of my sample data
Below is my intended result
d
Explanation:
If I choose the date range between 1 to 4 january 2018 canada will display 6 because it is summing up the value from row 10 and 14.
US will display 11 because it is summing the value from row 4 and 8.
Similarly, If I choose the date range between 1 to 3 January 2018, Canada will display 5 because it is summing up the value from row 10 and row 13.
i have created this measure:
Stock Measure = CALCULATE(sum(Sheet1[Stock]),generate(values(Sheet1[SubCategory]),LASTDATE(Sheet1[Date])))
however, for very large amount of distinct value subcategory (up to 1000 subcategroy), the measure performance is very slow and for some reason, lots of subcategory is excluded from the calculation. Also the total is showing up the wrong value as well
Any idea for the alternative approach ?
P.s. I can't use separate datedimension table, so the date filter is taken directly from transaction table
I have included the sample pbix as well
https://drive.google.com/file/d/1ogFH7U_VS0xcQavLIYdqTRjNqKNa1Fy8/view?usp=sharing
thank you
Solved! Go to Solution.
Hi,
Try this measure
=IF(HASONEVALUE(Sheet1[Location]),SUMX(SUMMARIZE(VALUES(Sheet1[SubCategory]),[SubCategory],"ABCD",CALCULATE(SUM(Sheet1[Stock]),LASTNONBLANK(Sheet1[Date],SUM(Sheet1[Stock])))),[ABCD]),SUMX(SUMMARIZE(VALUES(Sheet1[Location]),[Location],"EFGH",SUMX(SUMMARIZE(VALUES(Sheet1[SubCategory]),[SubCategory],"ABCD",CALCULATE(SUM(Sheet1[Stock]),LASTNONBLANK(Sheet1[Date],SUM(Sheet1[Stock])))),[ABCD])),[EFGH]))
Hi,
Try this measure
=SUMX(SUMMARIZE(VALUES(Sheet1[SubCategory]),[SubCategory],"ABCD",CALCULATE(SUM(Sheet1[Stock]),LASTNONBLANK(Sheet1[Date],SUM(Sheet1[Stock])))),[ABCD])
Hope this helps.
Thanks for the solution.
I have further question regarding your measure.
Where is the "ABCD" and [ABCD] come from ? is it the list of distinct value of subcategory ?
In the real production data, I will have more than 40000 distinct value of subcategory, therefore it might be difficult to hardcode all of it one by one
Thank you !
andre
Hi,
"ABCD" is just the title of the virtual column created via the SUMMARIZE() function. The number of distinct subcategories should not involve any additional work. Try to run this formula on your live data and let me know how it works.
Noted, Thanks for the ABCD explanation. I implemented your measure and it displayed same result like your capture.
However, one more problem is the total value is not correct (It supposed to show 15 instead 11 (i created one more simple KPI card to test it)
Thank you
Andre
Hi,
Try this measure
=IF(HASONEVALUE(Sheet1[Location]),SUMX(SUMMARIZE(VALUES(Sheet1[SubCategory]),[SubCategory],"ABCD",CALCULATE(SUM(Sheet1[Stock]),LASTNONBLANK(Sheet1[Date],SUM(Sheet1[Stock])))),[ABCD]),SUMX(SUMMARIZE(VALUES(Sheet1[Location]),[Location],"EFGH",SUMX(SUMMARIZE(VALUES(Sheet1[SubCategory]),[SubCategory],"ABCD",CALCULATE(SUM(Sheet1[Stock]),LASTNONBLANK(Sheet1[Date],SUM(Sheet1[Stock])))),[ABCD])),[EFGH]))
It works like a charm ! even my production data as well with millions of row
Thank you very much for your help !
Best regards
andre
You are welcome.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
124 | |
87 | |
85 | |
70 | |
51 |
User | Count |
---|---|
205 | |
153 | |
97 | |
79 | |
69 |