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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
shower999
Frequent Visitor

Lookupvalue Last Quarter in the same table without aggregation

Dear all,

 

I'm new to PowerBI DAX language.

I have a combined each month customer statuses and would like to compare their changes month over month. Customer is unique in each month

 

essentially, I want to  

1) lookup last month, profile status for the same customer and know the customer profile and warranty date

2) if customer is missing, it's off boarded and I need to flag it out

 

I am able to do this kind of lookup using Calculate (sum (last_data), DATEADD( date , -1, month)

 

but it need aggregation. I want this to be done in account level so I can count how many went up and down, warranty extended and slice/ fitler them when necessary.

 

hope you all can guide me. thank you in advance

 

 

Month1Data_dateAccountProfileLast_Mth_ProfileChangesWarranty_dateLast_Mth_W_DChanges
Jan1-JanMr. A1  1-Jan  
Feb1-FebMr. A31Up31-Dec1-JanExtended
Mar1-MarMr. A33 31-Dec31-Dec 
Jan1-JanMr. B3  31-Dec  
Feb1-FebMr. B13Down1-Jan1-JanCancelled
Mar1-Mar   Off boarded  Off boarded
2 ACCEPTED SOLUTIONS
v-yulgu-msft
Employee
Employee

Hi @shower999,

 

Please refer to below DAX formulas to add calculated columns:

Index =
RANKX (
    FILTER ( Sample1, Sample1[Account] = EARLIER ( Sample1[Account] ) ),
    Sample1[Data_date],
    ,
    ASC,
    DENSE
)

Last_Mth_Profile =
CALCULATE (
    SELECTEDVALUE ( Sample1[Profile] ),
    FILTER (
        ALLEXCEPT ( Sample1, Sample1[Account] ),
        Sample1[Index]
            = EARLIER ( Sample1[Index] ) - 1
    )
)

Profile_Changes =
IF (
    Sample1[Account] = BLANK (),
    "Off boarded",
    IF (
        Sample1[Last_Mth_Profile] = BLANK ()
            || Sample1[Last_Mth_Profile] = Sample1[Profile],
        BLANK (),
        IF ( Sample1[Last_Mth_Profile] < Sample1[Profile], "Up", "Down" )
    )
)

Last_Mth_W_D =
CALCULATE (
    SELECTEDVALUE ( Sample1[Warranty_date] ),
    FILTER (
        ALLEXCEPT ( Sample1, Sample1[Account] ),
        Sample1[Index]
            = EARLIER ( Sample1[Index] ) - 1
    )
)

Warranty_Changes =
IF (
    Sample1[Account] = BLANK (),
    "Off boarded",
    IF (
        Sample1[Last_Mth_W_D] = BLANK ()
            || Sample1[Last_Mth_W_D] = Sample1[Warranty_date],
        BLANK (),
        IF ( Sample1[Last_Mth_W_D] < Sample1[Warranty_date], "Cancelled", "Extended" )
    )
)

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
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

WoW!! this works perfectly. highly appreciated. I'll use these formulars across all my calculation.

 

View solution in original post

2 REPLIES 2
v-yulgu-msft
Employee
Employee

Hi @shower999,

 

Please refer to below DAX formulas to add calculated columns:

Index =
RANKX (
    FILTER ( Sample1, Sample1[Account] = EARLIER ( Sample1[Account] ) ),
    Sample1[Data_date],
    ,
    ASC,
    DENSE
)

Last_Mth_Profile =
CALCULATE (
    SELECTEDVALUE ( Sample1[Profile] ),
    FILTER (
        ALLEXCEPT ( Sample1, Sample1[Account] ),
        Sample1[Index]
            = EARLIER ( Sample1[Index] ) - 1
    )
)

Profile_Changes =
IF (
    Sample1[Account] = BLANK (),
    "Off boarded",
    IF (
        Sample1[Last_Mth_Profile] = BLANK ()
            || Sample1[Last_Mth_Profile] = Sample1[Profile],
        BLANK (),
        IF ( Sample1[Last_Mth_Profile] < Sample1[Profile], "Up", "Down" )
    )
)

Last_Mth_W_D =
CALCULATE (
    SELECTEDVALUE ( Sample1[Warranty_date] ),
    FILTER (
        ALLEXCEPT ( Sample1, Sample1[Account] ),
        Sample1[Index]
            = EARLIER ( Sample1[Index] ) - 1
    )
)

Warranty_Changes =
IF (
    Sample1[Account] = BLANK (),
    "Off boarded",
    IF (
        Sample1[Last_Mth_W_D] = BLANK ()
            || Sample1[Last_Mth_W_D] = Sample1[Warranty_date],
        BLANK (),
        IF ( Sample1[Last_Mth_W_D] < Sample1[Warranty_date], "Cancelled", "Extended" )
    )
)

1.PNG

 

Best regards,

Yuliana Gu

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

WoW!! this works perfectly. highly appreciated. I'll use these formulars across all my calculation.

 

Helpful resources

Announcements
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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