Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Anonymous
Not applicable

Running total between two selected periods

Hello,

I have a fact table with a relationship to a calendar table marked as Date table. Relation ship is one to n based on a date column.

I can create time intelligence clculations like YTD, Previsous year, previos period but I cannot create a running total that would work between two dates, i.e. If I select March to October of one of the year in the table I want to see the cumulative total starting with March value and ending in October as a running total.

It will not work, I tried several calculations, it is just replicating the value for the line not calculating the running total.
Formula 1
PTD Amount USD:=CALCULATE (
SUM(Bol[AmountUSD]);
FILTER (
ALL('Sailing Date'[Sailing Date]) ;
'Sailing Date'[Sailing Date] >= MIN('Sailing Date'[Sailing Date] )&&
'Sailing Date'[Sailing Date] <= MAX ('Sailing Date'[Sailing Date])))

 

Formula 2
Cumulative = CALCULATE (
SUM(Bol[AmountUSD]),
FILTER (
ALLSELECTED( 'BOL' ),
'Bol'[Sailing Date] >=MIN ('Sailing Date'[Sailing Date])&&
'Bol'[Sailing Date] <= MAX ( 'Bol'[Sailing Date] )))

 

I am not sure where to look at to find what is preventing these formulas to work as expected.

Any idea is appreciated, Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hello,

Thanks for all your suggestions. I finally found a way to calculate this running total using a formula like this one.

 

Cumulative Dollar :=
IF (
    MIN ( 'Dim_Calendar'[ID_Date] )
        <= CALCULATE ( MAX ( BOL[Sailing_Date_Key] ), ALL ( BOL ) );
CALCULATE(SUM(Bol[AmountUSD]),
Filter(
ALLSELECTED('Dim_Calendar'),'Dim_Calendar'[DateASDate]<=MAX('Dim_Calendar'[DateASDate])))
)

Which produces exactly the result I want

  YYYYWK  AmountUSD  Cumulative

2018461'327'2431'327'243
2018471'192'8902'520'134
2018481'604'9164'125'049
201849745'2564'870'306
20185020'7924'891'098
201851 4'891'098
201852 4'891'098
201901 4'891'098
201902 4'891'098
201903 4'891'098
201904 4'891'098
201905 4'891'098
201906 4'891'098
20190732'8344'923'932
201908 4'923'932
201909 4'923'932

View solution in original post

7 REPLIES 7
v-jiascu-msft
Employee
Employee

Hi @Anonymous,

 

Try this formula, please. The cause is the initial date is dynamic.

Measure 7 =
VAR minDate =
    CALCULATE (
        MIN ( 'Sailing Date'[Sailing Date] ),
        ALLSELECTED ( 'Sailing Date'[Sailing Date] )
    )
RETURN
    CALCULATE (
        Bol[AmountUSD],
        FILTER (
            ALL ( 'Sailing Date'[Sailing Date] ),
            'Sailing Date'[Sailing Date] >= minDate
                && 'Sailing Date'[Sailing Date] <= MAX ( 'Sailing Date'[Sailing Date] )
        )
    )

Running-total-between-two-selected-periods

 

 

Best Regards,
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

My running total should not have Running Total with date on rows. 

I should use Month Year. Format "May 2019".

As the solution use:

ALLSELECTED ( 'Sailing Date'[Sailing Date] )

 ALL ( 'Sailing Date'[Sailing Date] ),

 

I change to

ALLSELECTED ( 'Sailing Date') Without the column.

ALL ( 'Sailing Date') Without the column.

So it doesn't matter which column from calender table Used on rows, the Running Total will Work.

 

v-jiascu-msft/Dale , Thank you for your support and also Anonymous for creating the Post.

 

Best Regards

Amdi 

 

 

 

Anonymous
Not applicable

The code is:

Measure 7.2 = 
VAR minDate =
    CALCULATE (
        MIN ( 'Date_2'[Date] );
        ALLSELECTED ( Date_2)
    )
RETURN
    CALCULATE (
        [Sales Amount];
        FILTER (
            ALL ('Date_2'  );
            'Date_2'[Date] >= minDate
                && 'Date_2'[Date] <= MAX ( 'Date_2'[Date] )
        )
    ) 

Running Total_.JPG 

Anonymous
Not applicable

Hello,

I was able to get the running total calculation working. I can now select any time period and get the running total starting at the begining of the period.

PTD Amount USD:=
IF (
    MIN ('Sailing Date'[date_key])
        <= CALCULATE ( MAX ( BOL[Sailing_Date_Key] ); ALL (Bol ) );
CALCULATE(SUM(Bol[AmountUSD]);
Filter(
ALLSELECTED('Sailing Date');'Sailing Date'[Sailing Date]<=MAX('Sailing Date'[Sailing Date])))
)  

The result is like that

 YYYYWK   AmountUSD   Cumulative

2018461'327'2431'327'243
2018471'192'8902'520'134
2018481'604'9164'125'049
201849745'2564'870'306
20185020'7924'891'098
201851 4'891'098
20190732'8344'923'932
201908 4'923'932
201909 4'923'932
Anonymous
Not applicable

Hello,

Thanks for all your suggestions. I finally found a way to calculate this running total using a formula like this one.

 

Cumulative Dollar :=
IF (
    MIN ( 'Dim_Calendar'[ID_Date] )
        <= CALCULATE ( MAX ( BOL[Sailing_Date_Key] ), ALL ( BOL ) );
CALCULATE(SUM(Bol[AmountUSD]),
Filter(
ALLSELECTED('Dim_Calendar'),'Dim_Calendar'[DateASDate]<=MAX('Dim_Calendar'[DateASDate])))
)

Which produces exactly the result I want

  YYYYWK  AmountUSD  Cumulative

2018461'327'2431'327'243
2018471'192'8902'520'134
2018481'604'9164'125'049
201849745'2564'870'306
20185020'7924'891'098
201851 4'891'098
201852 4'891'098
201901 4'891'098
201902 4'891'098
201903 4'891'098
201904 4'891'098
201905 4'891'098
201906 4'891'098
20190732'8344'923'932
201908 4'923'932
201909 4'923'932

I had the same problem, it worked perfectly, thank you.

Omega
Impactful Individual
Impactful Individual

Can you please share a sample data? 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.