简体   繁体   中英

Creating Tags for Max / Min dates in Power BI DAX

I have the following table calculated table - QOL2:

In DAX Power BI I need to create a calculated columns RecentDate and LatestDate as shown on a screenshot:

Based on ClientID I need to tag latest date as "Max" in LatestDate column and earliest date as "Min" in [RecentDate] column (see screenshot)

If there is only one date (no highest or earliest date) - as it is for ClientID = 2666, then I need no tags!

在此处输入图像描述

I am using the following code, but it puts "Max" tag in RecentDate and "Min" tag in LatestDate:

      LatestDate = var LatestD = CALCULATE(Min(QOL2[Date]), ALLEXCEPT(QOL2, QOL2[ClientID]))   
                    return If(QOL2[Date]=LatestD && QOL2[Date]>1,"Min")  




     RecentDate = var RecentD = CALCULATE(Max(QOL2[Date]), ALLEXCEPT(QOL2,QOL2[ClientID]))                                                                                                                                                          
                   return If(QOL2[Date]=RecentD && QOL2[Date]>1,"Max") 
 

Please help!

I'm not sure why you need this as Calculate column, but you can do this like that:

RecentDate = var _client = 'Table'[ClientID]
var _min = calculate(min('Table'[Date]), FILTER(ALL('Table'), _client = 'Table'[ClientID]))
var _max = calculate(max('Table'[Date]), FILTER(ALL('Table'), _client = 'Table'[ClientID]))
return
if(_client = 'Table'[ClientID] && _min = 'Table'[Date] && _max <> _min, "MIN", BLANK())

LatestDate = var _client = 'Table'[ClientID]
var _min = calculate(min('Table'[Date]), FILTER(ALL('Table'), _client = 'Table'[ClientID]))
var _max = calculate(max('Table'[Date]), FILTER(ALL('Table'), _client = 'Table'[ClientID]))
return
if(_client = 'Table'[ClientID] && _max = 'Table'[Date] && _max <> _min, "MAX", BLANK())

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM