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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
Super User
Super User

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
Super User
Super User

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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