Forum Discussion

RP101's avatar
RP101
Frequent Visitor
1 year ago

YoY Variance Report by Month with dynamic header

Hi,

 

I have created a Year-over-Year (YoY) variance report by month and would like to enhance it with the following features:

  1. Add a dynamic header when a year is selected. I tried creating dynamic fields, but I am getting a blank value, and it ends up returning the variable itself as the header.
  2. Add a Year-to-Date (YTD) total before the Total row. This should display the total for the previous year, the current year, and the YoY change in units up to yesterday.
  3. I want to also see the Totals as is. 

YoY Variance pbix file 

 

 

Table = 

Client IDOrder DateItem NumberClient NameClient Request TypeUnits

1500029/1/2024ORT123ToysRUs CorporationAdd1
1400019/21/2024ABD123Amazon ABC LLCAdd1
1400019/22/2024ABC124Amazon XNY LLCAdd1
1500027/1/2024ORT123ToysRUs CorporationAdd1
1400017/21/2024ABD123Amazon ABC LLCAdd1
1400017/22/2024ABC124Amazon XNY LLCAdd1
1500028/1/2024ORT123ToysRUs CorporationAdd1
1500029/1/2023ORT123ToysRUs CorporationAdd1
1400019/21/2023ABD123Amazon ABC LLCAdd1
1400019/22/2023ABC124Amazon XNY LLCAdd1
1500027/1/2023ORT123ToysRUs CorporationAdd1
1400017/21/2023ABD123Amazon ABC LLCAdd1
1400017/22/2023ABC124Amazon XNY LLCAdd1
1500028/1/2023ORT123ToysRUs CorporationAdd1
1400018/21/2023ABD123Amazon ABC LLCAdd1
1400018/22/2023ABC124Amazon XNY LLCAdd1
1500028/1/2023ORT123ToysRUs CorporationAdd1
1700039/1/2024AOL123Ross IncCancel Order1
1800059/6/2024PAS123T-Mobile NJ LLCCancel Order1
1800059/6/2024PAS124T-Mobile NY LLCCancel Order1
1700037/1/2024AOL123Ross IncCancel Order1
1800057/6/2024PAS123T-Mobile NJ LLCCancel Order1
1800057/6/2024PAS124T-Mobile NY LLCCancel Order1
1700039/1/2023AOL123Ross IncCancel Order1
1800059/6/2023PAS123T-Mobile NJ LLCCancel Order1
1800059/6/2023PAS124T-Mobile NY LLCCancel Order1
1700037/1/2023AOL123Ross IncCancel Order1
1800057/6/2023PAS123T-Mobile NJ LLCCancel Order1
1800057/6/2023PAS124T-Mobile NY LLCCancel Order1
1700038/1/2023AOL123Ross IncCancel Order1
1800058/6/2023PAS123T-Mobile NJ LLCCancel Order1
1800058/6/2023PAS124T-Mobile NY LLCCancel Order1
2222229/21/202468562ATargetCreate Order1
2121219/22/202474432BMacysCreate Order1
2222227/21/202468562ATargetCreate Order1
2121217/22/202474432BMacysCreate Order1
2020208/26/202453620ALowesCreate Order1
2020208/27/202440058FHome DepotCreate Order1
2222228/21/202468562ATargetCreate Order1
2121218/22/202474432BMacysCreate Order1
2020208/26/202453620ALowesCreate Order1
2020208/27/202440058FHome DepotCreate Order1
2222229/21/202368562ATargetCreate Order1
2121219/22/202374432BMacysCreate Order1
2222227/21/202368562ATargetCreate Order1
2121217/22/202374432BMacysCreate Order1
2222228/21/202368562ATargetCreate Order1
2121218/22/202374432BMacysCreate Order1
2020208/26/202353620ALowesCreate Order1
2020208/27/202340058FHome DepotCreate Order1
2222228/21/202368562ATargetCreate Order1
2121218/22/202374432BMacysCreate Order1
2020208/26/202353620ALowesCreate Order1
2020208/27/202340058FHome DepotCreate Order1
1500028/1/2024ORT123ToysRUs CorporationLate Fee1
1400018/21/2024ABD123Amazon ABC LLCLate Fee1
1400018/22/2024ABC124Amazon XNY LLCLate Fee1
1500028/1/2024ORT123ToysRUs CorporationLate Fee1
1400018/22/2024ABC124Amazon XNY LLCLate Fee1
1800058/6/2024PAS123T-Mobile NJ LLCLate Fee1
1800058/6/2024PAS124T-Mobile NY LLCLate Fee1
1500028/1/2023ORT123ToysRUs CorporationLate Fee1
1400018/21/2023ABD123Amazon ABC LLCLate Fee1
1400018/22/2023ABC124Amazon XNY LLCLate Fee1
1500028/1/2023ORT123ToysRUs CorporationLate Fee1
1400018/22/2023ABC124Amazon XNY LLCLate Fee1
1800058/6/2023PAS123T-Mobile NJ LLCLate Fee1
1800058/6/2023PAS124T-Mobile NY LLCLate Fee1
1700038/1/2024AOL123Ross IncModify1
1800058/6/2024PAS123T-Mobile NJ LLCModify1
1800058/6/2024PAS124T-Mobile NY LLCModify1
1500028/1/2024ORT123ToysRUs CorporationModify1
1400018/21/2024ABD123Amazon ABC LLCModify1
1400018/22/2024ABC124Amazon XNY LLCModify1
1700038/1/2023AOL123Ross IncModify1
1800058/6/2023PAS123T-Mobile NJ LLCModify1
1800058/6/2023PAS124T-Mobile NY LLCModify1
1500028/1/2023ORT123ToysRUs CorporationModify1
1400018/21/2023ABD123Amazon ABC LLCModify1
1400018/22/2023ABC124Amazon XNY LLCModify1

 

 

Calendar =
Var Days = CALENDAR( MIN('Table'[Order Date]),MAX('Table'[Order Date]) )
RETURN ADDCOLUMNS(
    Days,
    "Year", YEAR([Date]),
    "Previous Year", YEAR ( [Date] )-1,
    "Month Number", MONTH([Date]),
    "Month Name", FORMAT([Date], "mmmm"),
    "Year Month Number", YEAR([Date]) * 12 + MONTH([Date]) - 1,
    "Year Month", FORMAT([Date], "mmm yy"),
    "Weekday", FORMAT ( [Date], "dddd" ),
    "Week Number", WEEKNUM([Date]),
    "Week Number of Year",WEEKNUM([Date],21),
    "Week Number and Year", "W" & WEEKNUM([Date]) & " " & YEAR([Date]),
    "WeekYearNumber", YEAR([Date]) & 100 + WEEKNUM([Date]),
    "Is working Day", not WEEKDAY([Date]) in {1,7},
    "Quarter", "Q" & TRUNC ( ( MONTH ( [Date] ) - 1 ) / 3 ) + 1
)
 
Current Year = YEAR(TODAY())
 
CurrYear =
CALCULATE (
    SUM('Table'[Units]),DATEADD('Calendar'[Date],0,YEAR)  
) + 0
 
PreYear =
CALCULATE (
    SUM('Table'[Units]),DATEADD('Calendar'[Date],-1,YEAR)  
) + 0
 
YoY % =
VAR CurrentYearValue = CALCULATE (
    SUM('Table'[Units]),DATEADD('Calendar'[Date],0,YEAR)  
) + 0

VAR PreviousYearValue = CALCULATE (
    SUM('Table'[Units]),DATEADD('Calendar'[Date],-1,YEAR)  
) + 0

RETURN
IF(
    NOT ISBLANK(PreviousYearValue),
    SWITCH(
        TRUE(),
        PreviousYearValue > 0 && CurrentYearValue = 0, -1, -- Case for previous value > 0 and current value = 0
        PreviousYearValue = 0 && CurrentYearValue > 0, 1,  -- Case for previous value = 0 and current value > 0
        PreviousYearValue = 0 && CurrentYearValue = 0, 0.00, -- Case for both values being 0
        DIVIDE(CurrentYearValue - PreviousYearValue, PreviousYearValue) -- Default case using DIVIDE
    ),
    BLANK()
)
 
 

 

Dynamic column header measure 

Current Year = YEAR(TODAY())
Previous Year = YEAR(TODAY())-1
Dynamic Fields = {
    ( SELECTEDVALUE('Calendar'[Year]), NAMEOF('Table'[CurrYear]), 0),
    ( SELECTEDVALUE('Calendar'[Year])-1, NAMEOF('Table'[PreYear]), 1),
    ("YoY %", NAMEOF('Table'[YoY %]), 2)
}
 Dynamic Fields is not gettting value from selectedvalue

 

 

 

 

 

I would appriciate any guidance ! 

Thanks,

RP

8 Replies

    • RP101's avatar
      RP101
      Frequent Visitor

      Hi danextian 

       

      Thanks for the quick reply ! I will check and see if it helps. how were you able to upload pibx files I was trying wanted to upload mine but didn't see any options. 

       

      • danextian's avatar
        danextian
        Super User

        Only superusers, CST and community admins can. You may post a link to files stored in the cloud though - just make sure they're publicly accessible/no need to request for permission.

  • RP101's avatar
    RP101
    Frequent Visitor

    Hi danextian 
    Thanks for the guidance I was able to get the dynamic header work but the column total is blank now, can you please check the PBI matrix and suggest solution how to fix it?

    YoY Variance 2.pbix


    I am also getting additional column Total which I want to remove. 

     

    Thanks in advanced !

    • danextian's avatar
      danextian
      Super User

      Are these measures addedd directly to the matrix or from a disconnected table column being referenced by a conditional measure?

       

      • RP101's avatar
        RP101
        Frequent Visitor

        Hi danextian 
        The measure named 'MyMeasure' was created under CustomPeriod and added to a matrix under Values. This matrix can be found on the third page of the pbix file. I attempted to use dynamic fields, but it didn't work, as shown on the second page. I hope this clarifies things. Apologies for any confusion.