Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi
Suppose that you want to count your customers
And that you just want to count those that has money in their account (This filter is easy and is applied in my code sample)
And sadly some of your customers pass away and you just want to count them as long as their alive (Scary ?)
In my sample I have tried to visualize what I am expecting.
My problem is in that I need to filter rows in my result based on if the customer is alive at this specific time or not.
The dateofdeath is in Dim_Customer, and present time is in Dim_Date, my filter would be something like Dim_Customer[DateOfDeath] > Dim_Date[PeriodDateTo] But this gives an error
SO how would you solve this problem?
Best Regards, Joakimscreenshot
@Lannersten Please try below measure and check if it works for you.
Measure =
VAR _customerId = SELECTEDVALUE('Fact'[CustomerId])
VAR _deathdate = CALCULATE(MAX(DimCustomer[Deathdate]),DimCustomer[CustomerId]=_customerId)
RETURN CALCULATE(DISTINCTCOUNT('Fact'[CustomerId]),'Fact'[Amount]>0,Dim_Date[To]<_deathdate)
Hi Vimal
I had an issue with the selectedvalue formula in Excel, but I retyped it like this:
NumOfCustomersAlive:=VAR _customerId = IF(HASONEVALUE('Facts'[CustomerId]);VALUES('Facts'[CustomerId]))
VAR _deathdate = CALCULATE(MAX(Dim_Customer[CalculatedDateOfDeath]);Dim_Customer[CustomerId]=_customerId)
RETURN CALCULATE(DISTINCTCOUNT('Facts'[CustomerId]);'Facts'[Amount]>0;Dim_Date[PeriodDatumTo]<_deathdate)
And it made the job, but when I added one more CustomerId to my facts table, the code fails. I guess it has to do with VAR _customerid just keeps one value ? Or? (In my production environment I have a couple of millions of customers...)
I have attached the result and my expected result + The data I'm using.
Do you suggest some other tweak to my code?
Best, Joakim
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
9 | |
9 | |
7 | |
6 | |
5 |
User | Count |
---|---|
20 | |
11 | |
10 | |
9 | |
6 |