cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
nsbars_rt
Advocate I
Advocate I

Grouping with condition

Hello

Please advise. Simple situation but I got stuck.

I have a table that looks like that:

s1.jpg

I need to group it by name, take min(OnDate)

and (here is the question) take the Department which was when date = min(OnDate)

If I do like:

testTable = SUMMARIZE('Table';'Table'[Name];"minDate";min('Table'[OnDate]);"minDept";min('Table'[Department]))
I get 
Grocery Department in grouping
which isn't what I want.
 
1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Hi @nsbars_rt ,

 

You can try to create a new calculated column using the if statement.

Column = 
VAR min_date = CALCULATE(MIN('TABLE'[ondate]),ALLEXCEPT('TABLE','TABLE'[name]))
return IF('TABLE'[ondate]=min_date,1)

You can filter on the table chart or create a new calculated table.

test_min_date.PNG

Table 2 = SELECTCOLUMNS(FILTER('TABLE','TABLE'[Column]=1),"name",'TABLE'[name],"ondate",'TABLE'[ondate],"department",'TABLE'[department])

test_min_date_2.PNG

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
V-lianl-msft
Community Support
Community Support

Hi @nsbars_rt ,

 

You can try to create a new calculated column using the if statement.

Column = 
VAR min_date = CALCULATE(MIN('TABLE'[ondate]),ALLEXCEPT('TABLE','TABLE'[name]))
return IF('TABLE'[ondate]=min_date,1)

You can filter on the table chart or create a new calculated table.

test_min_date.PNG

Table 2 = SELECTCOLUMNS(FILTER('TABLE','TABLE'[Column]=1),"name",'TABLE'[name],"ondate",'TABLE'[ondate],"department",'TABLE'[department])

test_min_date_2.PNG

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@nsbars_rt, Try lastnonblankvalue

https://docs.microsoft.com/en-us/dax/lastnonblankvalue-function-dax

 

lastnonblankvalue(Table[date],min(table[Department]))

Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

BizApps LATAM 2023

Business Application LATAM Summit 2023

Join the biggest FREE Business Applications Event in LATAM this February.

Power Platform Bootcamp

Global Power Platform Bootcamp

In this bootcamp we will deep-dive into Microsoft’s Power Platform stack with hands-on sessions and labs, delivered to you by experts and community leaders.