Forum Discussion
Cumulative calculation not returning data when no data for period selected
Hello,
I have some a table report where data is being displayed for the period selected (using date slider), and also cumulative data for each row groups. Cumulative calculation works fine except when there's no data for the period selected, as it should bring data from before the "From Date" in date slider.
So in the image above, we see cumulative data for Groups A,B and C. But when the slider date range selection is changed and there's no data for the period selected, the numbers disappear from the Cumulative columns like below (even though there's data that falls before the "From Date" in date slider:
Here's the formula I am using:
Cumulative Tested =
VAR _select=SELECTEDVALUE('vw_PRBI_Report_WeldRepairStats'[Project])
VAR _pStartDate = MINX(FILTER(ALL('vw_PRBI_Report_WeldRepairStats'),'vw_PRBI_Report_WeldRepairStats'[Project]=_select),[ProjectStartDate])
VAR _toDate=MAXX(ALLSELECTED('vw_PRBI_Report_WeldRepairStats'),'vw_PRBI_Report_WeldRepairStats'[TestedDate])
VAR __table =
SUMMARIZE('vw_PRBI_Report_WeldRepairStats',[MaterialGroup],"__value",
SUMX(
FILTER(ALL('vw_PRBI_Report_WeldRepairStats'),
'vw_PRBI_Report_WeldRepairStats'[TestedDate]>=_pStartDate &&
'vw_PRBI_Report_WeldRepairStats'[TestedDate]<=_toDate &&
'vw_PRBI_Report_WeldRepairStats'[Project]=_select &&
'vw_PRBI_Report_WeldRepairStats'[MaterialGroup] = SELECTEDVALUE('vw_PRBI_Report_WeldRepairStats'[MaterialGroup]))
,ISBLANK([Tested]) || [Tested] = 0, 0, [Tested])
)
)
RETURN
IF(
HASONEVALUE(vw_PRBI_Report_WeldRepairStats[MaterialGroup]),
SUMX(
FILTER(ALL('vw_PRBI_Report_WeldRepairStats'),
'vw_PRBI_Report_WeldRepairStats'[TestedDate]>=_pStartDate &&
'vw_PRBI_Report_WeldRepairStats'[TestedDate]<=_toDate &&
'vw_PRBI_Report_WeldRepairStats'[Project]=_select &&
'vw_PRBI_Report_WeldRepairStats'[MaterialGroup] = SELECTEDVALUE('vw_PRBI_Report_WeldRepairStats'[MaterialGroup]))
,ISBLANK([Tested]) || [Tested] = 0, 0, [Tested])
),
SUMX(__table,[__value])
)@v-yangliu-msft helped me on the cumulative calculation and got ideas from Greg_Deckler's link https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907 for displaying Cumulative totals in Total Row for this issue.
Thank you,
nhuda
- Anonymous2 years ago
Hi nhuda
Please try this:
First of all, add a new table:
Table = CALENDAR(MIN('vw_PRBI_Report_WeldRepairStats'[TestedDate]),MAX('vw_PRBI_Report_WeldRepairStats'[TestedDate]))Then I've made some changes to your original measure:
Cumulative Tested = VAR _Select = SELECTEDVALUE(vw_PRBI_Report_WeldRepairStats[Project]) VAR _pStartDate = MINX(FILTER(ALL('vw_PRBI_Report_WeldRepairStats'),'vw_PRBI_Report_WeldRepairStats'[Project]=_Select),[ProjectStartDate]) VAR _toDate=MAXX(ALLSELECTED('Table'),'Table'[Date]) VAR __table = SUMMARIZE('vw_PRBI_Report_WeldRepairStats',[MaterialGroup],"__value", SUMX( FILTER(ALL('vw_PRBI_Report_WeldRepairStats'), 'vw_PRBI_Report_WeldRepairStats'[TestedDate]>=_pStartDate && 'vw_PRBI_Report_WeldRepairStats'[TestedDate]<=_toDate && 'vw_PRBI_Report_WeldRepairStats'[Project]=_select && 'vw_PRBI_Report_WeldRepairStats'[MaterialGroup] = SELECTEDVALUE('vw_PRBI_Report_WeldRepairStats'[MaterialGroup])) ,IF(ISBLANK([Tested]) || [Tested] = 0, 0, [Tested]) ) ) RETURN IF( HASONEVALUE(vw_PRBI_Report_WeldRepairStats[MaterialGroup]), SUMX( FILTER(ALL('vw_PRBI_Report_WeldRepairStats'), 'vw_PRBI_Report_WeldRepairStats'[TestedDate]>=_pStartDate && 'vw_PRBI_Report_WeldRepairStats'[TestedDate]<=_toDate && 'vw_PRBI_Report_WeldRepairStats'[Project]=_select && 'vw_PRBI_Report_WeldRepairStats'[MaterialGroup] = SELECTEDVALUE('vw_PRBI_Report_WeldRepairStats'[MaterialGroup])) ,IF(ISBLANK([Tested]) || [Tested] = 0, 0, [Tested]) ), SUMX(__table,[__value]) )Then use the 'table'[date] as a slicer:
The result is as follow:
Best Regards
Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 Replies
- AnonymousNot applicable
Hi nhuda
How does this measure work? In my opinion, there should be some syntax errors in your formula.
Could you please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:
How to provide sample data in the Power BI Forum
How to Get Your Question Answered Quickly
And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.
How to upload PBI in Community
Best Regards
Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.- nhudaHelper II
Hi Anonymous ,
Here're some data:
Project ProjectStartDate MaterialGroup TestedDate Tested Project Abc 8/1/2021 A 8/1/2021 0 Project Abc 8/1/2021 A 8/1/2021 0 Project Abc 8/1/2021 A 9/17/2021 1 Project Abc 8/1/2021 A 9/17/2021 1 Project Abc 8/1/2021 A 9/17/2021 1 Project Abc 8/1/2021 A 9/17/2021 1 Project Abc 8/1/2021 A 10/26/2021 1 Project Abc 8/1/2021 A 10/26/2021 1 Project Abc 8/1/2021 A 12/10/2021 1 Project Abc 8/1/2021 A 12/10/2021 1 Project Abc 8/1/2021 A 7/25/2022 1 Project Abc 8/1/2021 A 7/25/2022 1 Project Abc 8/1/2021 A 7/25/2022 1 Project Abc 8/1/2021 A 7/25/2022 1 Project Abc 8/1/2021 A 7/25/2022 1 Project Abc 8/1/2021 A 7/25/2022 1 Project Abc 8/1/2021 A 7/25/2022 1 Project Abc 8/1/2021 A 7/28/2022 1 Project Abc 8/1/2021 A 7/28/2022 1 Project Abc 8/1/2021 A 7/28/2022 1 Project Abc 8/1/2021 A 7/29/2022 1 Project Abc 8/1/2021 A 7/29/2022 1 Project Abc 8/1/2021 A 7/29/2022 1 Project Abc 8/1/2021 A 7/29/2022 1 Project Abc 8/1/2021 A 7/29/2022 1 Project Abc 8/1/2021 A 7/29/2022 1 Project Abc 8/1/2021 A 7/29/2022 1 Project Abc 8/1/2021 A 7/29/2022 1 Project Abc 8/1/2021 A 7/31/2022 1 Project Abc 8/1/2021 A 7/31/2022 1 Project Abc 8/1/2021 A 7/31/2022 1 Project Abc 8/1/2021 A 7/31/2022 1 Project Abc 8/1/2021 A 7/31/2022 1 Project Abc 8/1/2021 A 7/31/2022 1 Project Abc 8/1/2021 A 7/31/2022 1 From the above data, expected outcome is like:
1) Period Selected - from August 1, 2021 to June 30, 2022
Period Tested Count - 8
Cumulative Tested Count - 8
2) Period Selected - from October 1, 2021 to June 30, 2022
Period Tested Count - 4
Cumulative Tested Count - 8
3) Period Selected - from January 1, 2022 to June 30, 2022
Period Tested Count - 0
Cumulative Tested Count - 8
However, I'd like to point out that - there is no issue with Scenarios 1 and 2. For Scenario 3, when Period Tested Count is 0 (no data), it doesn't return the Cumulative Tested Count as 8, it's just not returning anything (blank).
To confirm, the formula doesn't have syntax issues, it works but doesn't handle Scenario 3 above.
For pbix, how is it going to work without the data source. Is it like I export data to an excel and provide you with the excel data along with the pbix?
Please let me know.
Regards,
nhuda
- AnonymousNot applicable
Hi nhuda
Please try this:
First of all, add a new table:
Table = CALENDAR(MIN('vw_PRBI_Report_WeldRepairStats'[TestedDate]),MAX('vw_PRBI_Report_WeldRepairStats'[TestedDate]))Then I've made some changes to your original measure:
Cumulative Tested = VAR _Select = SELECTEDVALUE(vw_PRBI_Report_WeldRepairStats[Project]) VAR _pStartDate = MINX(FILTER(ALL('vw_PRBI_Report_WeldRepairStats'),'vw_PRBI_Report_WeldRepairStats'[Project]=_Select),[ProjectStartDate]) VAR _toDate=MAXX(ALLSELECTED('Table'),'Table'[Date]) VAR __table = SUMMARIZE('vw_PRBI_Report_WeldRepairStats',[MaterialGroup],"__value", SUMX( FILTER(ALL('vw_PRBI_Report_WeldRepairStats'), 'vw_PRBI_Report_WeldRepairStats'[TestedDate]>=_pStartDate && 'vw_PRBI_Report_WeldRepairStats'[TestedDate]<=_toDate && 'vw_PRBI_Report_WeldRepairStats'[Project]=_select && 'vw_PRBI_Report_WeldRepairStats'[MaterialGroup] = SELECTEDVALUE('vw_PRBI_Report_WeldRepairStats'[MaterialGroup])) ,IF(ISBLANK([Tested]) || [Tested] = 0, 0, [Tested]) ) ) RETURN IF( HASONEVALUE(vw_PRBI_Report_WeldRepairStats[MaterialGroup]), SUMX( FILTER(ALL('vw_PRBI_Report_WeldRepairStats'), 'vw_PRBI_Report_WeldRepairStats'[TestedDate]>=_pStartDate && 'vw_PRBI_Report_WeldRepairStats'[TestedDate]<=_toDate && 'vw_PRBI_Report_WeldRepairStats'[Project]=_select && 'vw_PRBI_Report_WeldRepairStats'[MaterialGroup] = SELECTEDVALUE('vw_PRBI_Report_WeldRepairStats'[MaterialGroup])) ,IF(ISBLANK([Tested]) || [Tested] = 0, 0, [Tested]) ), SUMX(__table,[__value]) )Then use the 'table'[date] as a slicer:
The result is as follow:
Best Regards
Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.