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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
AnFroyman
Frequent Visitor

Same period last year - blank - line chart

Hello, 

 

I want a line chart with a running total of this year, and a separate line of the running total of previous year.

A first issue I encounter is that with below DAX formula, there are 'gaps' in the LY running total (when the running total last year did not change day after day, this happens).

 

Running Total =
ROUND(CALCULATE(
    SUM([sales]),
    FILTER(
        ALLSELECTED('Calendar'[Date]),
        ISONORAFTER('Calendar'[Date], MAX('Calendar'[Date]), DESC)
    )
),2)
 
Running Total LY =
CALCULATE([Running Total],ALL('Calendar'[Date]),DATEADD('Calendar'[Date],-1,YEAR))

 

I work with a separate date table...

 

Eg, on the LY running total, there is a blank value for 08/05/2023, but in 2022 there was a value (the same as the day before)
2023-09-04_16h33_59.png

 

The next issue is that the line graph of the last year running total is different from the real running total of last year (as seen in the 2022 running total orange line). This probably has something to do with the gaps in the LY running total?


AnFroyman_0-1693838211585.png

 

 

1 ACCEPTED SOLUTION

hi @AnFroyman 

 

Here you go,

 

Step 1

cal_running total this year =
CALCULATE (
    SUMX ( Facts,Facts[Amount]),
    FILTER (
        ALL ('Calendar'  ),
       'Calendar'[Day of Year]  <= MAX ( 'Calendar'[Day of Year] )
         
          && 'Calendar'[MonthNum]  <= MAX ( 'Calendar'[MonthNum])

            && 'Calendar'[Year] = SELECTEDVALUE('Calendar'[Year])
    )
)

 

 

 

Step 2

cal_running total last year =
CALCULATE (
    SUMX ( Facts,Facts[Amount]),
    FILTER (
        ALL ('Calendar'  ),
       'Calendar'[Day of Year]  <= MAX ( 'Calendar'[Day of Year] )
         
          && 'Calendar'[MonthNum]  <= MAX ( 'Calendar'[MonthNum])

            && 'Calendar'[Year] = SELECTEDVALUE('Calendar'[Year]) -1
    )
)
 
Looks like it is working
ribisht17_0-1694521591105.png

 

Ritesh

Mark my post as a solution if it helped you| Munde and Kudis (Ladies and Gentlemen) I like your Kudos!! !!
My YT Channel Dancing With Data !! Connect on Linkedin !!Power BI for Tableau Users 
 

View solution in original post

12 REPLIES 12
ribisht17
Community Champion
Community Champion

hi @AnFroyman 

 

Can you share the sample dataset/pbix file so that we can test it ?

 

Regards,

Ritesh

 

@ribisht17 how exactly do I share a file here?

Also, don't you think that the other values (non blank), even those are not correct ?

dropbox or google drive link

Please try this DAX

 

Running Total LY without DateCalc =
CALCULATE(
    SUM('Facts'[Amount]),
    FILTER
    (
        ALLSELECTED('Calendar'[Date]),
        ('Calendar'[Date]) < MAX('Calendar'[Date])&&
        YEAR('Calendar'[Date]) < MAX('Calendar'[Date])
         
         )
    )


Hi @ribisht17, it now looks like it is presenting the running total of yesterday instead of last year?

hi @AnFroyman 

 

Here you go,

 

Step 1

cal_running total this year =
CALCULATE (
    SUMX ( Facts,Facts[Amount]),
    FILTER (
        ALL ('Calendar'  ),
       'Calendar'[Day of Year]  <= MAX ( 'Calendar'[Day of Year] )
         
          && 'Calendar'[MonthNum]  <= MAX ( 'Calendar'[MonthNum])

            && 'Calendar'[Year] = SELECTEDVALUE('Calendar'[Year])
    )
)

 

 

 

Step 2

cal_running total last year =
CALCULATE (
    SUMX ( Facts,Facts[Amount]),
    FILTER (
        ALL ('Calendar'  ),
       'Calendar'[Day of Year]  <= MAX ( 'Calendar'[Day of Year] )
         
          && 'Calendar'[MonthNum]  <= MAX ( 'Calendar'[MonthNum])

            && 'Calendar'[Year] = SELECTEDVALUE('Calendar'[Year]) -1
    )
)
 
Looks like it is working
ribisht17_0-1694521591105.png

 

Ritesh

Mark my post as a solution if it helped you| Munde and Kudis (Ladies and Gentlemen) I like your Kudos!! !!
My YT Channel Dancing With Data !! Connect on Linkedin !!Power BI for Tableau Users 
 

@ribisht17 lots of kudos for your effort, very glad with the result!

Glad that it helped!!

🙂

ribisht17
Community Champion
Community Champion

hi @AnFroyman 

 

Have you tried this  https://learn.microsoft.com/en-us/dax/sameperiodlastyear-function-dax ?

 

Regards,

Ritesh

Mark my post as a solution if it helped you| Munde and Kudis (Ladies and Gentlemen) I like your Kudos!! !!
My YT Channel Dancing With Data !! Connect on Linkedin !!Power BI for Tableau Users 

@ribisht17 thanks for your reply. Indeed, the sameperiodlastyear function returns the same behaviour (blanks).

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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