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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
kalkhudary
Helper IV
Helper IV

Variance between current and last year based on a year slicer from Calendar Table

Hello All, 

 

I have a data model that includes 4 fact tables connected to a calender table through a YearMonth Index preserved on all the 4 fact tables and in the calender table. These tables are connected to the calendar table through a many-to-many relationship (see below the concept) with a single cross-filter direction from Calander to fact table. No relationship is required between the 4 fact tables meaning they don't need to read from each other data anything. It is only that each one connects to the Calander Table to utilize a global year slicer.

 

Test.PNG

 

My issue comes here. I want to create a dax based on the global Year slicer. When I select a year in the Global Year slicer (2024) from calander Table, I want to see the variance % of calls received based on the last year (2023).

 

I have daxed this but there is something wrong, it is giving me 100% which is not the case, it should show 2.5% based on the values I have. Any step - by step help would be great, stuck on it for a day now.

Calls Received Variance % =
VAR Up_Arrow = UNICHAR(9650)
Var Down_Arrow = UNICHAR(9660)
VAR SelectedCallsReceivedLY = CALCULATE(SUM('Table1'[Value]), 'Tabl1'[Year]=(SELECTEDVALUE('Calendar Table'[Year-Global Filter]))-1, 'Table1'[Indicator]= "Calls received")
VAR CallsReceivedCurrentYear =
CALCULATE(SUM('Table1'[Value]),'Table1'[Indicator]="Calls received")
VAR Difference = CallsReceivedCurrentYear - SelectedCallsReceivedLY
VAR CallsReceivedPercentage = FORMAT(DIVIDE(Difference, CallsReceivedCurrentYear,0),"0.0%")

RETURN if(Difference<0,"-"&CallsReceivedPercentage&" " &Down_Arrow& "  from LY", "+"&CallsReceivedPercentage&" "&Up_Arrow& "  from LY")
1 ACCEPTED SOLUTION

Hi @kalkhudary 

 

I conduct the following tests based on the data you provided and some of the content described in the original article:

 

Calls Received Variance % = 
VAR Up_Arrow = UNICHAR(9650)
VAR Down_Arrow = UNICHAR(9660)
VAR SelectedYear = SELECTEDVALUE('Calendar Table'[Year-Global Filter])
VAR SelectedCallsReceivedLY = 
    CALCULATE(
        SUM('Table1'[Value]), 
        'Table1'[Year] = SelectedYear - 1, 
        'Table1'[Indicator] = "Number of calls received"
    )
VAR CallsReceivedCurrentYear = 
    CALCULATE(
        SUM('Table1'[Value]), 
        'Table1'[Year] = SelectedYear, 
        'Table1'[Indicator] = "Number of calls received"
    )
VAR Difference = CallsReceivedCurrentYear - SelectedCallsReceivedLY
VAR CallsReceivedPercentage = 
    FORMAT(
        DIVIDE(Difference, SelectedCallsReceivedLY, 0), 
        "0.0%"
    )

RETURN 
    IF(
        Difference < 0, 
        "-" & CallsReceivedPercentage & " " & Down_Arrow & " from LY", 
        "+" & CallsReceivedPercentage & " " & Up_Arrow & " from LY"
    )

 

Here is the result.

 

vnuocmsft_0-1739778063935.png

 

Hope this helps you.

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
kalkhudary
Helper IV
Helper IV

@v-nuoc-msft Worked perfectly. thanks so much. I also figured out that if I want to look at the last year current month, I can add the Filter(All(Table1 (date)) 

v-nuoc-msft
Community Support
Community Support

Hi @kalkhudary 

 

To calculate the variance percentage of calls received based on the last year, you need to ensure that your DAX formula correctly captures the values for the current year and the previous year.

 

The issue in your formula seems to be with the calculation of , where you are filtering the year directly in the  function. This might not be working as expected because the context transition might not be properly applied.

 

Try this:

 

Calls Received Variance % =
VAR Up_Arrow = UNICHAR(9650)
VAR Down_Arrow = UNICHAR(9660)
VAR SelectedYear = SELECTEDVALUE('Calendar Table'[Year-Global Filter])
VAR CallsReceivedCurrentYear =
    CALCULATE(
        SUM('Table1'[Value]),
        'Table1'[Indicator] = "Calls received",
        'Calendar Table'[Year-Global Filter] = SelectedYear
    )
VAR SelectedCallsReceivedLY =
    CALCULATE(
        SUM('Table1'[Value]),
        'Table1'[Indicator] = "Calls received",
        SAMEPERIODLASTYEAR('Calendar Table'[Date])
    )
VAR Difference = CallsReceivedCurrentYear - SelectedCallsReceivedLY
VAR CallsReceivedPercentage = DIVIDE(Difference, SelectedCallsReceivedLY, 0)

RETURN 
    IF(
        Difference < 0,
        "-" & FORMAT(CallsReceivedPercentage, "0.0%") & " " & Down_Arrow & " from LY",
        "+" & FORMAT(CallsReceivedPercentage, "0.0%") & " " & Up_Arrow & " from LY"
    )

 

If you're still having problems, provide some dummy data and the desired outcome. It is best presented in the form of a table.

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-nuoc-msft Thanks for the above. The idea of using sameperiodlastyear is good too. I tried but it is stilll not working. I want also to account for the fact if I want to look a previous Month previous year when selected the year from the global filter. 

Here is sample of dataset for one table that is connected to the Calender Table through the Index column: Table 1 connected to Calender table through the index column

Table1:

IndicatorValueYearMonthIndexYearMonthDayDate
Number of calls received25902023120230101/01/23January 2023
Number of calls received24552023220230202/01/23February 2023
Number of calls received28772023320230303/01/23March 2023
Number of calls received28012023420230404/01/23April 2023
Number of calls received40032023520230505/01/23May 2023
Number of calls received41432023620230606/01/23June 2023
Number of calls received43482023720230707/01/23July 2023
Number of calls received38502023820230808/01/23August 2023
Number of calls received36772023920230909/01/23September 2023
Number of calls received331420231020231010/01/23October 2023
Number of calls received267920231120231111/01/23November 2023
Number of calls received264920231220231212/01/23December 2023
Number of calls received32602024120240101/01/24January 2024
Number of calls received27032024220240202/01/24February 2024
Number of calls received28952024320240303/01/24March 2024
Number of calls received35222024420240404/01/24April 2024
Number of calls received42852024520240505/01/24May 2024
Number of calls received44692024620240606/01/24June 2024
Number of calls received48212024720240707/01/24July 2024
Number of calls received44282024820240808/01/24August 2024
Number of calls received35812024920240909/01/24September 2024
Number of calls received340320241020241010/01/24October 2024
Number of calls received305520241120241111/01/24November 2024

Calender Table built in Query - this is sample but includes from year 2020 till 2025

DateYear-Global FilterMONTHMonthNameQuarterDayOfWeekDayNameIndex
07/07/202320237JulyQ35Friday202307
07/14/202320237JulyQ35Friday202307
07/21/202320237JulyQ35Friday202307
07/28/202320237JulyQ35Friday202307

 

Hi @kalkhudary 

 

I conduct the following tests based on the data you provided and some of the content described in the original article:

 

Calls Received Variance % = 
VAR Up_Arrow = UNICHAR(9650)
VAR Down_Arrow = UNICHAR(9660)
VAR SelectedYear = SELECTEDVALUE('Calendar Table'[Year-Global Filter])
VAR SelectedCallsReceivedLY = 
    CALCULATE(
        SUM('Table1'[Value]), 
        'Table1'[Year] = SelectedYear - 1, 
        'Table1'[Indicator] = "Number of calls received"
    )
VAR CallsReceivedCurrentYear = 
    CALCULATE(
        SUM('Table1'[Value]), 
        'Table1'[Year] = SelectedYear, 
        'Table1'[Indicator] = "Number of calls received"
    )
VAR Difference = CallsReceivedCurrentYear - SelectedCallsReceivedLY
VAR CallsReceivedPercentage = 
    FORMAT(
        DIVIDE(Difference, SelectedCallsReceivedLY, 0), 
        "0.0%"
    )

RETURN 
    IF(
        Difference < 0, 
        "-" & CallsReceivedPercentage & " " & Down_Arrow & " from LY", 
        "+" & CallsReceivedPercentage & " " & Up_Arrow & " from LY"
    )

 

Here is the result.

 

vnuocmsft_0-1739778063935.png

 

Hope this helps you.

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

A proper calendar table is based on a Date column as the primary key, and uses 1:* relationships. Once you have that corrected you can use the standard time intelligence DAX functions.

@lbendlin I do have a date column in The Calender table but I used the index column in the calender table to connect to the other tables while also needing to use the calender table Year to slice. That is of an unual scenario I agree but that was given. Any thought on how to improve the above data model shared based on given scenario and tables provided.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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