cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
LuciaZel
Frequent Visitor

Floating cumulative sum

Hi everyone, 

 

I am new in Power BI and DAX, so I would like to ask a question. 

 

I have this table "Krist":

Rok = Year from dat_prov column; Mesiac = Month from dat_prov column, prov - súčet = sum of prov column

LuciaZel_1-1677771209868.png

 

I need to calculate floating cumulative sum of "prov", which means the summary of all amount in date period 12 previous months. 

 

I created DAX statement:

dat_prov = date of prov

 

cumulative_prov_12M =
CALCULATE(
    SUM(Krist[prov]),
    ALL(Krist),
    DATESBETWEEN(
        Krist[dat_prov].[Date],
    DATEADD(LASTDATE(Krist[dat_prov].[Date]),-12,MONTH),
    LASTDATE(Krist[dat_prov].[Date])))
 
And I got the result right
LuciaZel_2-1677771339773.png

 

When I transform table into line graph and I want to select in graph just period of date I can not do that. As you can see below on the second screen the "prov-súčet" is filtered by period of time (1.3.2022 - 28.2.2023), but the cumulative line is not. 

LuciaZel_3-1677771515808.pngLuciaZel_4-1677771569605.png

 

Is there anything wrong with the DAX statement or how can I solve it? 

Thanks for answers.

 

 

1 ACCEPTED SOLUTION
andhiii079845
Solution Sage
Solution Sage

I build a example with your infos. I think the problem is your automatic time intelligence. 
For example: If you use the automatic time intelligence filter: blue one the filtering is correct. If you use the regular date column it not work. The time intelligence is like a hidden dimension table for the date. (please correct me someone if its wrong). 
starting point:

andhiii079845_2-1677829904893.png

blue filtering (date - year):

andhiii079845_3-1677830032548.png

The same via date (red). You see the cummlative has no filter.

andhiii079845_5-1677830232732.png

The reason is, that you use ALL() in your DAX expression and the measure line ignore your filter (via selection the regular date column!) from the fact table. If you use the "hidden" dimension table filter via other fields the complete table is filtered for both (measure and column).

 

View solution in original post

5 REPLIES 5
andhiii079845
Solution Sage
Solution Sage

I build a example with your infos. I think the problem is your automatic time intelligence. 
For example: If you use the automatic time intelligence filter: blue one the filtering is correct. If you use the regular date column it not work. The time intelligence is like a hidden dimension table for the date. (please correct me someone if its wrong). 
starting point:

andhiii079845_2-1677829904893.png

blue filtering (date - year):

andhiii079845_3-1677830032548.png

The same via date (red). You see the cummlative has no filter.

andhiii079845_5-1677830232732.png

The reason is, that you use ALL() in your DAX expression and the measure line ignore your filter (via selection the regular date column!) from the fact table. If you use the "hidden" dimension table filter via other fields the complete table is filtered for both (measure and column).

 

Thank you very much it works, you are a hero 🙂

LuciaZel_1-1677831776515.png

 

Can I have one more question? 

How can I select in graph just 12 previous months to show? The result should be, that I will connect our Database to Power BI and every month it should show new data for actual month and 11 previous months. 

 

For example, today is the 3th of March 2023, so I want to see on graph data for 12 closed months, which means from march 2022 to february 2023 and it should float every month, so on the 3th of april 2023 it should show data in graph from april 2022 to march 2023, etc. 

 

How can I select it in filter please? 

 

LuciaZel_0-1677831399114.png

 

Please, do not forget to flag my reply as a solution. Thank you 🙂

I would give you the advice to create a regular dimensional table for the calendar/date and disable this auto time intelligence. Than you will have all possilities to get the result you want.

andhiii079845
Solution Sage
Solution Sage

Can you please give the complete DAX statement of:

I created DAX statement:
dat_prov = date of prov

 

Hi, 

 

sorry I used the wrong interpretation. Column "dat_prov" is regular column from imported table "Krist":

LuciaZel_0-1677828577412.png

In power query I just changed the type to date and then transformed all the date into start of the month

LuciaZel_1-1677828661161.png

LuciaZel_2-1677828745611.png

 

 

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

MPPC 2023 PBI Carousel

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors
Top Kudoed Authors