Forum Discussion

mrklucz's avatar
mrklucz
Regular Visitor
3 years ago
Solved

Relative time measures with Dynamic Time axis

Hi,

 

I'm having an issue with a measure with relative time period.

 

My model is having dateTable and factTable with a relationship.

 

My measure looks like:

Measure= 
VAR CurrentMonth =    
CALCULATE(
    SUM(factTable[Actual])
)
VAR SamePeriodPreviousYear =
CALCULATE(
    SUM(factTable[Actual]),
    SAMEPERIODLASTYEAR(dateTable[Date])
   )

RETURN
DIVIDE(
	CurrentMonth-SamePeriodPreviousYear,
	SamePeriodPreviousYear)

There is a requirement to provide a table with dynamically changing to Months/Quarters/Years

 

I created additional table with dates which contains Date, DatePart, DateDisplay, Order - as A result I got a table with all 

potential dates, dateparts and display dates- and created a relationship to dateTable many-to-one in both directions.

 

I created a matrix table:

- in rows I have my KPIs

- in columns I have my Date display (from calculated table)

- values (my Actuals)

 

All is good when I'm using simple measures with no time-intelligence functions. Quarters/Months/Years are chaninging dynamically and present a proper data, but I have an issue that my measure for sameperiodlastyear doesn't work at all and present blanks. 

 

Additionaly, this model is used for multiple other reports - so changing the formula is not an option, as this would need to get through a whole uat and approval processes. This dynamically changing time axis (column) is a requirement for only this report.

 

How can I overcome this?

  • mrklucz's avatar
    mrklucz
    3 years ago

    amitchandak it was not an option since I'm using a live connection to AAS, but I managed to resolve this issue. 

     

    I created a table 'DatesWithPartsYear' that combines dates, DisplayDates, PartOfYear as a seperate table (no connection to the model) and then re-caluclated my measure for this report to.

     

    In DateTable I created additional columns "Year Month" and "Year Quarter" - to follow the same data schema as in DatesWithPartsYear. then in my measers I added TREATAS - to treat my displayDate as a specific column from ch_date depends on context ot PartYear.

     

     

     

    Actual = 
    SWITCH(
        VALUES ( DatesWithPartsYear[PartYear] ),
        "Month",
            CALCULATE(
                SUM(factTable[Value]),
                factTable[MeasureTypeName] = "Actual",
                TREATAS ( VALUES ( v_DatesWithPartsYear[DisplayDate] ) , dateTable[Year Month])
            ),
        "Quarter",
            CALCULATE(
                SUM(factTable[Value]),
                factTable[MeasureTypeName] = "Actual",
                TREATAS ( VALUES ( DatesWithPartsYear[DisplayDate] ) , dateTable[Year Quarter])
            )
        )

     

     

     

2 Replies

    • mrklucz's avatar
      mrklucz
      Regular Visitor

      amitchandak it was not an option since I'm using a live connection to AAS, but I managed to resolve this issue. 

       

      I created a table 'DatesWithPartsYear' that combines dates, DisplayDates, PartOfYear as a seperate table (no connection to the model) and then re-caluclated my measure for this report to.

       

      In DateTable I created additional columns "Year Month" and "Year Quarter" - to follow the same data schema as in DatesWithPartsYear. then in my measers I added TREATAS - to treat my displayDate as a specific column from ch_date depends on context ot PartYear.

       

       

       

      Actual = 
      SWITCH(
          VALUES ( DatesWithPartsYear[PartYear] ),
          "Month",
              CALCULATE(
                  SUM(factTable[Value]),
                  factTable[MeasureTypeName] = "Actual",
                  TREATAS ( VALUES ( v_DatesWithPartsYear[DisplayDate] ) , dateTable[Year Month])
              ),
          "Quarter",
              CALCULATE(
                  SUM(factTable[Value]),
                  factTable[MeasureTypeName] = "Actual",
                  TREATAS ( VALUES ( DatesWithPartsYear[DisplayDate] ) , dateTable[Year Quarter])
              )
          )