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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
IrishChristof
Frequent Visitor

Total Sales up to a point in time (NOT TOTALYTD)

Hi all,

 

I have been scouring the internet trying to find a solution to my problem, but as yet cannot find one.

Basically I was wondering if there was any DAX that would calculate (in the below example) total Passengers up to 10th May rather than just the 10th of May.

But I dont want to use a formula like this... 

 

=CALCULATE(TOTALYTD([Passengers],DatesList1[Date]),DatesList1[Date]=today())

...as that will only give me Passengers booked between 1st of Jan and 10th of May.

 

Then for the second part, I'd also like to see Passengers this time last year.

Again, the YTD formula wont work 

=CALCULATE(TOTALYTD([Passengers],DatesList1[Date]),DatesList1[Date]=(today()-365))

as it will only give me 1st of Jan to 10th May last year.

 

So I guess I need something like DATESBETWEEN formula maybe, but I can't seem to figure them out. 

 

Any help would be greatly appreciated 🙂

 

 

biq.png

 

1 ACCEPTED SOLUTION

@IrishChristof  here are the new measures

 

RT TY = CALCULATE( [Total Sales], FILTER( ALL( 'Calendar'[Date] ), 'Calendar'[Date] <= MAX( 'Calendar'[Date] ) && 'Calendar'[Date] <= TODAY() ) ) 
 RT PY = 
 VAR __maxDate = CALCULATE( MAX( 'Calendar'[Date] ) ,
 DATEADD( 
        CALCULATETABLE(
            VALUES('Calendar'[Date]),
            KEEPFILTERS( 'Calendar'[Date] <= TODAY() )
        ), 
        -1,
        YEAR 
    ) 
)
RETURN 
CALCULATE( [Total Sales], FILTER( ALL( 'Calendar'[Date] ), 'Calendar'[Date] <= MAX( 'Calendar'[Date] ) && 'Calendar'[Date] <= __maxDate ) ) 


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

4 REPLIES 4
parry2k
Super User
Super User

@IrishChristof this will do it

 

Sales PY = 
TOTALYTD(
    [Passengers], 
    DATEADD( 
        CALCULATETABLE(
            VALUES(DateList1[Date]),
            KEEPFILTERS( DateList1[Date] <= TODAY() )
        ), 
        -1,
        YEAR 
    ) 
)


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thanks for the reply, but this is still giving a Jan 1st - May 10th result.

What i want to see is anything from day0 (eg: 1st Jan 1900) through to the day selected on the slider (in this case 10th May 2019).

 

Then another DAX that will tell me, up to the same time last year.. eg: Day0 through to 10th May 2018 in this case

 

The YTD formulas are great, but not for this particular task.

 

Thanks again

Chris

 

@IrishChristof  here are the new measures

 

RT TY = CALCULATE( [Total Sales], FILTER( ALL( 'Calendar'[Date] ), 'Calendar'[Date] <= MAX( 'Calendar'[Date] ) && 'Calendar'[Date] <= TODAY() ) ) 
 RT PY = 
 VAR __maxDate = CALCULATE( MAX( 'Calendar'[Date] ) ,
 DATEADD( 
        CALCULATETABLE(
            VALUES('Calendar'[Date]),
            KEEPFILTERS( 'Calendar'[Date] <= TODAY() )
        ), 
        -1,
        YEAR 
    ) 
)
RETURN 
CALCULATE( [Total Sales], FILTER( ALL( 'Calendar'[Date] ), 'Calendar'[Date] <= MAX( 'Calendar'[Date] ) && 'Calendar'[Date] <= __maxDate ) ) 


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

This works beautifully.

Thank you so much!! 🙂

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors