Forum Discussion
Cumulative calculation not returning data when no data for period selected
- 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.
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.
- nhuda2 years agoHelper 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
- Anonymous2 years agoNot 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.- nhuda2 years agoHelper II
Hi Anonymous ,
Sorry for the delay in answering you, I was away for 7 days.
I just tried your formulae and it's making the Cumulative number contant irrespective of changes to both the "From" and "To" dates selected in the Date Selector. It should go higher when "To" date is changed (and there's additional data). When only "From" date is changed in the selector, it should stay the same because from the begiining of the Project to the "To" date we have the same number of Tested.
Not sure why you got the good result and mine is not good.
But I appreciate your time and effort to resolve my issue.
Regards,
nhuda