cancel
Showing results for
Did you mean:

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Frequent Visitor

## Date Analysis

Hi,

I have the following situation that I need help with. The objective is to compare Platinum with Silver Plan Dates. For each GroupMemberID of the same value in the Platinum plan, identify the Silver plan that has the minimum closest date (on or after) to the row with the Platinum plan. Once a Silver date is idenitified it cannot be used again when iterating onto the next row with the Platinum plan. Is there a way to do this with DAX?

 GroupId GroupMemberId Employee Coverage Plan Date Expected Results Column System.Object[] M001 Platinum 4/22/2014 X System.Object[] M001 Platinum 11/29/2014 System.Object[] M001 Silver 6/5/2015 X System.Object[] M002 Platinum 7/10/2014 X System.Object[] M002 Platinum 10/12/2014 System.Object[] M002 Silver 8/18/2014 X System.Object[] M003 Platinum 9/11/2015 System.Object[] M003 Platinum 9/28/2014 X System.Object[] M003 Silver 6/7/2015 X System.Object[] M004 Platinum 12/1/2015 System.Object[] M004 Platinum 11/30/2014 X System.Object[] M004 Platinum 3/14/2014 X System.Object[] M004 Silver 3/25/2014 X System.Object[] M004 Silver 8/18/2015 X System.Object[] M005 Platinum 11/9/2014 X System.Object[] M005 Silver 11/29/2014 X System.Object[] M006 Platinum 11/13/2014 X System.Object[] M006 Platinum 5/1/2015 System.Object[] M006 Platinum 11/13/2014 X System.Object[] M006 Platinum 6/13/2014 System.Object[] M006 Silver 5/1/2014 System.Object[] M006 Silver 11/13/2014 X

Thank you

3 REPLIES 3
Community Support

You can create a calculated column as below to get it, please find the details in the attachment.

``````Column =
VAR _silverdate =
CALCULATE (
MAX ( 'Table'[Date] ),
FILTER (
'Table',
'Table'[GroupId] = EARLIER ( 'Table'[GroupId] )
&& 'Table'[GroupMemberId] = EARLIER ( 'Table'[GroupMemberId] )
&& 'Table'[Employee Coverage Plan] = "Silver"
)
)
VAR _ptdate =
CALCULATE (
MAX ( 'Table'[Date] ),
FILTER (
'Table',
'Table'[GroupId] = EARLIER ( 'Table'[GroupId] )
&& 'Table'[GroupMemberId] = EARLIER ( 'Table'[GroupMemberId] )
&& 'Table'[Employee Coverage Plan] = "Platinum"
&& 'Table'[Date] <= _silverdate
)
)
RETURN
IF (
( 'Table'[Employee Coverage Plan] = "Silver"
&& 'Table'[Date] = _silverdate )
|| ( 'Table'[Employee Coverage Plan] = "Platinum"
&& 'Table'[Date] = _ptdate ),
"X"
)``````

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Frequent Visitor

It appears that the filtering is brining up all dates where the silver plan is on or after the platinum date. In another words, I need 1 from platinum and 1 from silver. After that iterate through the remaining lines in the group.

Community Champion

To achieve your objective of comparing Platinum with Silver Plan Dates and identifying the Silver plan with the minimum closest date for each GroupMemberID, you can use DAX (Data Analysis Expressions) in Power BI or other similar tools. You'll need to create a calculated column or measure that performs the necessary calculations. Below is the suggested approach:

Assuming you have a table named "CoveragePlans" with columns: GroupId, GroupMemberId, Employee, Coverage Plan, and Date, and you want to create a new column named "Expected Results Column":

You can use the following DAX expression for the "Expected Results Column":

Expected Results Column =
VAR CurrentGroupMemberId = CoveragePlans[GroupMemberId]
VAR CurrentDate = CoveragePlans[Date]
VAR CurrentCoveragePlan = CoveragePlans[Employee Coverage Plan]

RETURN
IF (
CurrentCoveragePlan = "Platinum",
VAR MinSilverDate =
CALCULATE (
MIN ( CoveragePlans[Date] ),
FILTER (
CoveragePlans,
CoveragePlans[GroupMemberId] = CurrentGroupMemberId &&
CoveragePlans[Employee Coverage Plan] = "Silver" &&
CoveragePlans[Date] >= CurrentDate &&
NOT ( CoveragePlans[Date] IN { CurrentDate } )
)
)
RETURN
IF (
ISBLANK ( MinSilverDate ),
BLANK (),
"X"
),
BLANK ()
)

This expression first filters the rows where the coverage plan is "Platinum". For each Platinum plan row, it looks for the minimum date in the "Silver" plans that belong to the same GroupMemberId, are on or after the current Platinum date, and have not been used before. If a minimum Silver date is found, it returns "X"; otherwise, it returns BLANK().

You can add this DAX expression to a calculated column in your Power BI data model, or you can adapt it to use as a measure depending on your reporting requirements.

Please adjust the table and column names accordingly based on your actual data model. This DAX expression assumes that the data structure is similar to what you've provided.

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

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

Announcements

#### New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

#### Power BI Monthly Update - May 2024

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

#### Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors