Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hi everyone actually i was trying to find Distinct customer count in dax i have one table is test in that i want to find distinct count of customer whose last year sales less than zero and current year sales is greater than zero for eg.if customer 4 had not done sales in last year and in current year he had done sales then count as one else zero so i want to make it dynamic so if select april and year 2023 then it should calculate presvious year start of the month means april 2022 to current selectded month minus one means till march 2022 cumulative sales. if i select june 2023 then it should caluculate cumulative sales from april 2022 to may 2023
TEST :-
Customer | Month | Year | Region | Sales |
1 | April | 2022 | east | 1200 |
2 | May | 2022 | west | 1400 |
3 | Feb | 2022 | south | 1400 |
2 | April | 2023 | west | 1300 |
4 | June | 2023 | north | 1200 |
5 | august | 2023 | east | 5000 |
Solved! Go to Solution.
I tried it, but it doesn't work; it returns a blank value. So I generated one date column with the assistance of the month and year columns, and then I established one table, Dates, with the aid of which I created a new measure.
previous sales=
To achieve this in DAX (Data Analysis Expressions), you can create a calculated column or measure in your Power BI or other DAX-supported tool. Here's an example measure that you can use to calculate the distinct customer count based on your conditions:
DistinctCustomerCount =
CALCULATE(
DISTINCTCOUNT('TEST'[Customer]),
FILTER(
VALUES('TEST'[Customer]),
CALCULATE(
SUM('TEST'[Sales]),
FILTER(
'TEST',
'TEST'[Year] = YEAR(MAX('TEST'[Year])) - 1 &&
'TEST'[Month] <= MAX('TEST'[Month])
)
) < 0 &&
CALCULATE(
SUM('TEST'[Sales]),
FILTER(
'TEST',
'TEST'[Year] = YEAR(MAX('TEST'[Year])) &&
'TEST'[Month] <= MAX('TEST'[Month])
)
) > 0
)
)
This measure first filters the customers based on your conditions (last year sales < 0 and current year sales > 0). It then calculates the distinct count of customers meeting these conditions.
You can use this measure in your report, and it will dynamically adjust based on the selected month and year.
Remember to replace 'TEST' with the actual name of your table if it's different. Also, ensure that the 'Month' column is in a format that allows proper comparison (e.g., as a number or a properly sorted text format).
Feel free to adapt the measure based on your specific data model and requirements.
I tried it, but it doesn't work; it returns a blank value. So I generated one date column with the assistance of the month and year columns, and then I established one table, Dates, with the aid of which I created a new measure.
previous sales=
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 |
---|---|
15 | |
11 | |
11 | |
10 | |
10 |
User | Count |
---|---|
19 | |
14 | |
13 | |
11 | |
8 |