Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Measure to calculate the latest dayid for each record which is not greater than the filter selected

Dear Community, 

I'm currently facing a challenge in resolving the following issue.
1. I need to find the max (day_id) for each record based on user slicer in Power BI. 
2.  then count the  distinct subscriptionid's with respect to status on above criteria

 

My data looks something like this:

Table1:

Subscription_idDay_idStatus
12345620200101Active
12345720200105Cancel
12345620200118Frozen
12345720200203Frozen
12378920200208Active
12345620200228Active
12347820200301Frozen
12378020200210Active

 

 

I'm trying to acheive some thing like this:

 

if user selects day_id as 20200115 (jan -15-2020), it should display below records

Subscription_idDay_idStatusMax_day_id
12345620200101Active20200101
12345720200105Cancel20200105

 

Count of active -1;

Count of Cancel -1;

 

if user selects day_id as 20200130 (jan -30-2020), it should display below records

Subscription_idDay_idStatusMax_day_id
12345620200101Active20200118
12345720200105Cancel20200105
12345620200118Frozen20200118

 

Count of active -0;

Count of Cancel -1;
count of Frozen - 1;


if user selects day_id as 20200211 (Feb-11-2020), it should display below records

Subscription_idDay_idStatusMax_day_id
12345620200101Active20200118
12345720200105Cancel20200203 
12345620200118Frozen20200118
12345720200203Frozen20200203 
12378920200208Active20200208
12378020200210Active20200210

 

Count of active -2;

Count of Cancel -0;
count of Frozen - 2;


It's surely silly, but please help!!

4 REPLIES 4
amitchandak
Super User
Super User

@Anonymous , Create a measure like this and use

Measure =
VAR __id = MAX ( 'Table'[Subscription_id] )
VAR __date = CALCULATE ( MAX( 'Table'[Day_id] ), ALLSELECTED ( 'Table' ), 'Table'[Subscription_id] = __id )
RETURN CALCULATE ( Max ( 'Table'[Status] ), VALUES ( 'Table'[Subscription_id] ), 'Table'[Subscription_id] = __id, 'Table'[Day_id] = __date )

Anonymous
Not applicable

Hey @amitchandak , 

 

Thanks for you quick response. It works as expected.

 

Just as an add on, can we get this measure to show only the latest records instead of showing whole data? 

@Anonymous , if only one record

 

Measure =
VAR __id = MAX ( 'Table'[Subscription_id] )
RETURN CALCULATE ( Max ( 'Table'[Status] ), 'Table'[Day_id] = __date )

Anonymous
Not applicable

Awesome. Thanks!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.