Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

Table Visual and Measure Breaks when Adding Another Column

I don't know how else to title this problem, but this is the best I've got. 

 

I have a dataset as follows, where I have Locations (TRT_ID) that could have one of two Metrics (Metric_Type), which has monthly data (Use). 

 

TRT_IDMetric_TypeDateUseCompleted
19Electricity2022/1/18566Yes
19Electricity2022/2/18052Yes
19Electricity2022/3/19334Yes
19Electricity2022/4/18681Yes
19Electricity2022/5/17529Yes
19Electricity2022/6/19166Yes
19Electricity2022/7/19350Yes
19Electricity2022/8/111342Yes
19Electricity2022/9/10No
19Natural Gas2022/1/1166.72Yes
19Natural Gas2022/2/1138.16Yes
19Natural Gas2022/3/1338.44Yes
19Natural Gas2022/4/147.12Yes
19Natural Gas2022/5/110Yes
19Natural Gas2022/6/10.36Yes
19Natural Gas2022/7/10.71Yes
19Natural Gas2022/8/10.36Yes
19Natural Gas2022/9/1 No
22Electricity2022/1/17405.86Yes
22Electricity2022/2/17166.25Yes
22Electricity2022/3/112397.47Yes
22Electricity2022/4/15691.83Yes
22Electricity2022/5/16619.3Yes
22Electricity2022/6/15988.94Yes
22Electricity2022/7/16640.56Yes
22Electricity2022/8/16154.99Yes
22Electricity2022/9/1 No

 

I have a second table that houses information on the location: TRT_ID, Site_Name, etc. , which has an active relationship with Table 1 through TRT_ID

 

I have created a measure that calculates the Z-Score, grouping by both TRT_ID and Metric Type (i.e. I want z-scores for Jan-Sep usage of electricity for Location 19), and my table currently looks like this. 

 

Final_Zscore = 

VAR FinalAverage = CALCULATE(

    AVERAGE ( Metrics_Outlier[Use] ),

    ALLEXCEPT ( Metrics_Outlier, Environmental_Data_Collection_Locations[Site_Name], Metrics_Outlier[TRT_ID], Metrics_Outlier[Metric_Type] )

    )

VAR FinalSTDev = CALCULATE(

    STDEVX.P( Metrics_Outlier, Metrics_Outlier[Use] ),

    ALLEXCEPT ( Metrics_Outlier, Environmental_Data_Collection_Locations[Site_Name], Metrics_Outlier[TRT_ID], Metrics_Outlier[Metric_Type] )

)

Return

 (SUM(Metrics_Outlier[Use])- FinalAverage)/FinalSTDev

 

Everything is FINE, until I try to add "Month" from the date hierarchy. Then suddenly all my values start repeating and everything just breaks. 

 

 

I understand that I need to somehow account for the date in the measure, but I just can't figure out what it is that needs to be changed/added to the measure for it to essentially ignore the "date" column completely, so I can just keep it in there for my user's reference. 

5 Replies

  • lukiz84's avatar
    lukiz84
    Memorable Member

    what if you add the date column to your ALLEXCEPT modifier?

    • Anonymous's avatar
      Anonymous
      Not applicable

      I get repeat rows no matter what mix of date I put into the allexcept of the measure

      Use data w/out average column: 

       

       

      Table when I add the average column

       

       

      Measure w/ date in AllExcept (I also tried pulling just the month from the Full Date's date hierarchy, AND having a month-only column ) : 

       

       

       

  • Hi,

    Try this approach

    1. Create a Calendar Table with calculated column formulas for year, Month name and Month number.

    2. Sort the Month name column by the Month number.

    3. Create a relationship from the Date column of Metrics_Outlier table to Date column of the Calendar Table

    4. To your visual, drag Year and Month name from the Calendar Table

    5. Your measures can be simplified to

    Finalsum = SUM(Metrics_Outlier[Use])

    FinalAverage = AVERAGE(Metrics_Outlier[Use])

    FinalSTDev = STDEVX.P( Metrics_Outlier, Metrics_Outlier[Use] )

    Final_Zscore = divide(([Finalsum]- [FinalAverage]),[FinalSTDev])

    Hope this helps.

     

  • Aburar_123's avatar
    Aburar_123
    Solution Supplier

    Hi Anonymous ,

     

    Please add Month column also in that AllExcept() function.

    • Anonymous's avatar
      Anonymous
      Not applicable

      I've tried this in multiple iterations, and I keep getting repeat rows. 

       

      Use data w/out average column: 

       

      Table when I add the average column

       

      Measure w/ date in AllExcept (I also tried pulling just the month from the Full Date's date hierarchy, AND having a month-only column 😞