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

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

Reply
Barry_Sophus
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?

 

GroupIdGroupMemberIdEmployee Coverage PlanDateExpected Results Column
System.Object[]M001Platinum4/22/2014X
System.Object[]M001Platinum11/29/2014 
System.Object[]M001Silver6/5/2015X
System.Object[]M002Platinum7/10/2014X
System.Object[]M002Platinum10/12/2014 
System.Object[]M002Silver8/18/2014X
System.Object[]M003Platinum9/11/2015 
System.Object[]M003Platinum9/28/2014X
System.Object[]M003Silver6/7/2015X
System.Object[]M004Platinum12/1/2015 
System.Object[]M004Platinum11/30/2014X
System.Object[]M004Platinum3/14/2014X
System.Object[]M004Silver3/25/2014X
System.Object[]M004Silver8/18/2015X
System.Object[]M005Platinum11/9/2014X
System.Object[]M005Silver11/29/2014X
System.Object[]M006Platinum11/13/2014X
System.Object[]M006Platinum5/1/2015 
System.Object[]M006Platinum11/13/2014X
System.Object[]M006Platinum6/13/2014 
System.Object[]M006Silver5/1/2014 
System.Object[]M006Silver11/13/2014X

 

Thank you

3 REPLIES 3
v-yiruan-msft
Community Support
Community Support

Hi @Barry_Sophus ,

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"
    )

vyiruanmsft_0-1708410539147.png

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.

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.

123abc
Community Champion
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.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.