Sum where version is highest by another variable (no max version in the whole data)

后端 未结 1 811
小鲜肉
小鲜肉 2021-01-23 00:01

I\'m struggling having this measure to work.

I would like to have a measure that will sum the Value only for the max version of each house.

So following this exa

相关标签:
1条回答
  • 2021-01-23 00:53

    I use "Data" as a name of your table.

    Sum of Latest Values =
    VAR Latest_Versions =
        SUMMARIZE ( Data, Data[House_id], "Latest_Version", MAX ( Data[Version_Id] ) )
    
    VAR Latest_Values =
        TREATAS ( Latest_Versions, Data[House_id], Data[Version_Id] )
    
    VAR Result =
        CALCULATE ( SUM ( Data[Value] ), Latest_Values )
    
    RETURN Result
    

    Measure output:

    How it works:

    1. We calculate a virtual table of house_ids and their max versions, and store it in a variable "Latest_Versions"
    2. We use the table from the first step to filter data for the latest versions only, and establish proper data lineage (https://www.sqlbi.com/articles/understanding-data-lineage-in-dax/)
    3. We calculate the sum of latest values by filtering data for the latest values only.

    You can learn more about this pattern here: https://www.sqlbi.com/articles/propagate-filters-using-treatas-in-dax/

    0 讨论(0)
提交回复
热议问题