Forum Discussion
Running Weekly Total Combining Two Data Sources
- Anonymous3 years ago
Hi MiloPowerBI ,
Here I create a sample to have a test.
Measure:
Running Total = VAR _CURRENTYEARWEEK = YEAR ( TODAY () ) * 100 + WEEKNUM ( TODAY (), 1 ) VAR _GENERATE = GENERATE ( CALCULATETABLE ( VALUES ( 'Calendar'[YearWeek] ), ALL ( 'Calendar' ) ), CALCULATETABLE ( VALUES ( Actual[Product] ), ALL ( Actual[Product] ) ) ) VAR _ADD = ADDCOLUMNS ( _GENERATE, "Value", IF ( 'Calendar'[YearWeek] < _CURRENTYEARWEEK, CALCULATE ( SUM ( Actual[Value] ), FILTER ( Actual, Actual[YearWeek] = EARLIER ( [YearWeek] ) && Actual[Product] = EARLIER ( [Product] ) ) ) + 0, CALCULATE ( SUM ( Plan[Value] ), FILTER ( Plan, Plan[YearWeek] = EARLIER ( [YearWeek] ) && Plan[Product] = EARLIER ( [Product] ) ) ) ) ) VAR _MIN = CALCULATE ( MIN ( Actual[YearWeek] ), ALLEXCEPT ( Actual, Actual[Product] ) ) VAR _MAX = CALCULATE ( MAX ( Plan[YearWeek] ), ALLEXCEPT ( Plan, Plan[Product] ) ) RETURN IF ( MAX ( 'Calendar'[YearWeek] ) >= _MIN && MAX ( 'Calendar'[YearWeek] ) <= _MAX, SUMX ( FILTER ( _ADD, [Product] = MAX ( Actual[Product] ) && [YearWeek] <= MAX ( 'Calendar'[YearWeek] ) ), [Value] ) )Result is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
Please show the expected outcome based on the sample data you provided.
https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523
- MiloPowerBI3 years agoFrequent Visitor
Hello lbendlin,
Apologies, I am pretty new around here and didnt realise if I could upload files with data in them. Will take this lesson forward for next time. Thank you for the helpful links.