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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
jwisrael
Frequent Visitor

Question on relative time

I'm looking to create a custom column based on a date range to show customer activity.
Active = last invoice date within last four months
Active B= last invoice date within last 5-8 months
Active c= last invoice date  within last 9-12 months
Inactive = last invoice date beyond 12months.
 
I can't seem to figure out the best way to do this, any help or guidance would be appreciated,
 
Thank you,
2 ACCEPTED SOLUTIONS
mahoneypat
Microsoft Employee
Microsoft Employee

Please try a column expression like this (DAX column, not a query column)

 

Invoice Status =
VAR vMonthsOld =
    DATEDIFF (
        Table[InvoiceDate],
        TODAY (),
        MONTH
    )
VAR vResult =
    SWITCH (
        TRUE (),
        vMonthsOld <= 4"Active",
        vMonthsOld <= 8"Active A",
        vMonthsOld <= 12"Active B",
        "Inactive"
    )
RETURN
    vResult

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

mahoneypat
Microsoft Employee
Microsoft Employee

Yes.  I think you could replace the vMonthsOld variable with

 

vMonthsOld = CALCULATE(MAX('P21&IBS Data'[Date]), ALLEXCEPT('P21&IBS Data', 'P21&IBS Data'[CustomerName]))

 

If not, please share some representative mock data for a modified solution.

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

4 REPLIES 4
mahoneypat
Microsoft Employee
Microsoft Employee

Yes.  I think you could replace the vMonthsOld variable with

 

vMonthsOld = CALCULATE(MAX('P21&IBS Data'[Date]), ALLEXCEPT('P21&IBS Data', 'P21&IBS Data'[CustomerName]))

 

If not, please share some representative mock data for a modified solution.

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


I eneded up creating another date column for last invocie date and using that in the model you provided. Worked great, plus I can have a column that tells me their exact last invoice dat. I appreciate your help, thank you.

 

JW

mahoneypat
Microsoft Employee
Microsoft Employee

Please try a column expression like this (DAX column, not a query column)

 

Invoice Status =
VAR vMonthsOld =
    DATEDIFF (
        Table[InvoiceDate],
        TODAY (),
        MONTH
    )
VAR vResult =
    SWITCH (
        TRUE (),
        vMonthsOld <= 4"Active",
        vMonthsOld <= 8"Active A",
        vMonthsOld <= 12"Active B",
        "Inactive"
    )
RETURN
    vResult

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thank you! This worked great, however, because my data goes line by line with invoices, this just bases it on where the date falls with that specific invoice. Is there a way to highlight the relative time from last invoice date by customer name within the expression you sent? I tried adding this into the expression, 

Last Customer Invoice Date = CALCULATE(LASTDATE('P21&IBS Data'[Date]), ALLEXCEPT('P21&IBS Data','P21&IBS Data'[CustomerName])).
 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors