Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
I'm trying to create a measure where I'm counting the distinct clients from a vendor where the client has bought something in the selected month and also in the other two months before. Example: the select month is august and the client has to have sales in august and also in july or june. What i tried to use but is not working:
Active Clients=
Hi, @mayara_alencar
Thanks for the reply from divyed and Jihwan_Kim. You can try the following dax to achieve your need.
Active =
VAR _slicerMonth = SELECTEDVALUE(Slicer[month])
VAR _earlierMonth = _slicerMonth - 2
VAR _month = SELECTEDVALUE('Table 1'[month])
VAR _result = IF(_month>=_earlierMonth && _month <=_slicerMonth,CALCULATE(COUNTROWS('Table 2'),FILTER('Table 2','Table 2'[Active?] = "Active")))
RETURN
_result
Inactive =
VAR _slicerMonth = SELECTEDVALUE(Slicer[month])
VAR _earlierMonth = _slicerMonth - 2
VAR _month = SELECTEDVALUE('Table 1'[month])
VAR _result = IF(_month>=_earlierMonth && _month <=_slicerMonth,CALCULATE(COUNTROWS('Table 2'),FILTER('Table 2','Table 2'[Active?] = "Inactive")))
RETURN
_result
Best Regards,
Yang
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
Hello @mayara_alencar ,
You can mofiy your dax to achieve the goal :
Active Clients =
VAR SelectedMonth = SELECTEDVALUE(vw_sales[StartOfMonth]) -- The selected month
VAR DateRange =
DATESINPERIOD(
vw_sales[StartOfMonth],
SelectedMonth,
-2,
MONTH
) -- Create a 3-month range including the selected month and 2 prior months
RETURN
CALCULATE(
DISTINCTCOUNT(vw_sales[codclient]), -- Count distinct clients
FILTER(
vw_sales,
vw_sales[StartOfMonth] IN DateRange && -- Check if the StartOfMonth falls within the range
vw_sales[Sales R$] > 0 -- Ensure there are sales
)
)
Modify variable and column names as per need.
I hope this helps.
Did I answer your query ? Mark this as solution if this helps, Kudos are appreciated.
Cheers
This one didn't work. It only counted the clients that have sales>0 in the current month. It should count the ones that also have sales in the 2 previous months.
Hi,
I tried to create a sample pbix file like below, and please check the below picture and the attached pbix file whether it suits.
Client count: =
VAR _t = SUMMARIZE ( sales, client[client] )
RETURN
COUNTROWS ( _t )
WINDOW function (DAX) - DAX | Microsoft Learn
Client count also in the otehr two months before: =
VAR _t =
WINDOW (
-2,
REL,
0,
REL,
ALL ( 'calendar'[Year-Month], 'calendar'[Year-Month sort] ),
ORDERBY ( 'calendar'[Year-Month sort], ASC )
)
RETURN
CALCULATE ( [Client count:], _t )
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
This also didn't work 😢
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
13 | |
12 | |
8 | |
7 | |
7 |
User | Count |
---|---|
20 | |
14 | |
11 | |
10 | |
10 |