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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
smpa01
Super User
Super User

Show running total against date table but only till the max period in transaction

I am working with three tables and the schema is following (pbix is attached)

smpa01_1-1638824449456.png

 

 

'Calendar' filters 'Transactions' through 'key'.

 

I am trying to show a running total from transactions by bringing X axis from calendar. But I want this running total to display till the max period I have in my transactions.

 

I am currently doing this

smpa01_2-1638824525798.png

 

But I want this cause the max period in transaction is 202104

smpa01_3-1638824588736.png

Off course, I can do this but it wipes out the total

smpa01_4-1638824773116.png

 

What is an elegant way to achieve this? 

Thank you in advance

@AlexisOlson 

 

 

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

I'm not sure why there's an intermediate 'key' table but you can use it or 'Transaction' as a tablefilter for your max date.

runningTotal = 
VAR _maxDate = CALCULATE ( MAX ( 'Calendar'[Date] ), 'key' )
RETURN
    CALCULATE (
        SUM ( Transactions[Sale] ),
        'Calendar'[Date] <= _maxDate
    )

 

View solution in original post

3 REPLIES 3
smpa01
Super User
Super User

@AlexisOlson  Thanks for this. I did not see this sort of table application before. Is there any blog post or anything from SQLBI explaining this?

I do have a follow up Q though

 

I pushed your solution little further to test one more idea to see if instead of passing a `Transactions` table, whether it is possible to pass on a FIltered `transactions` table.

 

I ingested one row in each Key and Transaction table for Year=2020 data and I wanted to see if there is a way to calculate on running total for Transactions[Year]=2021 and Transactions[period]<=202104.

 

smpa01_0-1638833518902.png

 

smpa01_1-1638833541141.png

 

 

The normal measure is this

 

runningTotal = 
VAR _mxP =
    CALCULATE(MAX ( 'Calendar'[period] ),Transactions)
VAR _runningT=
    CALCULATE (
        SUM ( Transactions[Sale] ),
         'Calendar'[period] <= _mxP 
    )
RETURN _runningT

 

 

smpa01_2-1638833577974.png

 

I changed to this

 

runningTotal = 
VAR _mxP =
    CALCULATE(MAX ( 'Calendar'[period] ),FILTER(Transactions,Transactions[Year]=2021))
VAR _runningT=
    CALCULATE (
        SUM ( Transactions[Sale] ),
         'Calendar'[period] <= _mxP 
    )
RETURN _runningT

 

smpa01_3-1638833630466.png

 

which did not give me what I wanted, so I tried like this

 

runningTotal = 
VAR _mxP =
    CALCULATE(MAX ( 'Calendar'[period] ),Transactions)
VAR _runningT=
    CALCULATE (
        SUM ( Transactions[Sale] ),
         'Calendar'[period] <= _mxP , Transactions[Year]=2021
    )
RETURN _runningT

 

 

smpa01_4-1638833974060.png

 

Do you have any possible explanation?

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

This article talks about this sort of filtering a bit:
https://www.sqlbi.com/articles/filtering-tables/

 

I'm not quite sure what part you're requesting an explanation for. Adding a year = 2021 filter doesn't change what the maximal date is so it won't affect the result unless it's part of the filter context when calculating the sum.

AlexisOlson
Super User
Super User

I'm not sure why there's an intermediate 'key' table but you can use it or 'Transaction' as a tablefilter for your max date.

runningTotal = 
VAR _maxDate = CALCULATE ( MAX ( 'Calendar'[Date] ), 'key' )
RETURN
    CALCULATE (
        SUM ( Transactions[Sale] ),
        'Calendar'[Date] <= _maxDate
    )

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors