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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Mr_Robot0092
Frequent Visitor

Changing the context filter based inside a calculation

Hello,

 

I have a dimension that have the status of client(Active,inactive,...) , and i have a fact table that contains all my client with the status id and date key.

The status of client can change every day.

I have a report with a slicer on date and also some other filter in other dimension.

I have a table that show me the count of my client of each status .

 

 

NB Client	Status
17132		 ACTIVE
1530	     INACTIVE
152            N/A

 

What i want is calculate the NB Client of each status and Adding and New status called Last Day Inactive  that show me the Nb Client that are inactive in my last Date of my filter.

Example : 

In my slicer i selected two Date from 1/04/2022 to 10/04/2022 .

The idea is calculate the NB Client in my Last Date in my case 10/04/2022 and showing the value , i want something like as bellow :

 

 

NB Client	Status
17132		 ACTIVE
1530	     INACTIVE
152            N/A
15	    Last Day INACTIVE

 

 

What i did , i create Calculated table "DimStatusTR" based on my Dimension table like this : 

 

UNION (
    ROW (
        "Status_Key", "99",
        "Status_Label", "Last Day Inactive"
    ),
    SUMMARIZECOLUMNS (
        'DimStatus'[Status_Key],
        'DimStatus'[Status_Label]
    )
)

 

 

I did a relationship between this new dimension and my Fact table , after that , i created a measure like as bellow : 

Var _InactiveLAstDay  = CALCULATE(
    [NbClient],
    FILTER(
        Fact_Client,
        RELATED('DimStatusTR'[Status_Label]) = "Inactive" &&
        Fact_Client[Date_Key] = MAX(Fact_Client[Date_Key])
    )
)


Var _OtherStatus = [NbClient]

Var _current = SELECTEDVALUE('DimStatusTR'[Status_Label])

Var result = if(_current ="Last Day Inactive",_InactiveLAstDay  +0,_OtherStatus)

Return result

 

The result that i get is like as bellow : 

NB Client	Status
17132		 ACTIVE
1530	     INACTIVE
152            N/A
0             Last Day INACTIVE

 

What i want is something like that 

NB Client	Status
17132		 ACTIVE
1530	     INACTIVE
152            N/A
15	    Last Day INACTIVE

 

Any idea how can i do that ?

 

Thanks for help ! 

2 REPLIES 2
amitchandak
Super User
Super User

@Mr_Robot0092 , First of all you need a date wise status for that. Now you can have column on meausre for what you need

 

Like the last status column 

=

var _max = maxx(filter(Table, [NB Client] = earlier([NB Client])  && [Date]  < Earlier([Date]) ) , [Date])

return

maxx(filter(Table, [NB Client] = earlier([NB Client])  && [Date]  =_max ) , [Status])

 

for measure refer

Power BI Abstract Thesis: How to use two Date/Period slicers

https://youtu.be/WSeZr_-MiTg

 

Day Intelligence - Last day, last non continous day
https://medium.com/@amitchandak.1978/power-bi-day-intelligence-questions-time-intelligence-5-5-5c324...

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hello @amitchandak 

 

Thanks for replying .I tried to do your code but doesn't work i this [NB Client] = earlier([NB Client]) i have this error the parameter is not not the correct type .

The [NB Client] is measure with Distinctcount(client_id)
Any idea ?

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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