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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Dynamic filter values

Hello everyone,

 

I have an issue to correctly count the distinct products within dynamic filter options.

This is my simple data model which consists of only one table.

NorbertL_1-1599468787157.png

In the first column of my matrix I need to create a measure that calculates the number of products per country for the earliest available date and so far it's pretty easy.

I did it with following DAX expression and it is working:

 

M1 =
var _date = FIRSTDATE(Table[Creation Date])
var _value = CALCULATE(DISTINCTCOUNT(Table[Product Number]), Table[Creation Date]=_date)
RETURN IF(ISBLANK(_value),0,_value)
 

My result:

Adnotacja 2020-09-07 112036.png

But the problem occurs when I need to create the second measure which consists of the same conditions as the first one but additionaly there need to be following condition: 

 

For Denmark, count only products which have value "DK Trade" in 'Sales Channel' column but in case of France, count only products which have value "FR Retail" in 'Sales Channel' column (It can be hard-coded which sales channel for which country).

 

I was trying to do something like below but it doesnt work.

 

M2 =
var _date = FIRSTDATE(Table[Creation Date])
var _value = CALCULATE(DISTINCTCOUNT(Table[Product Number]), Table[Creation Date]=_date,
Table[Sales Channel] = IF (Table[Country] = "Denmark", "DK Trade",
                                      IF (Table[Country] = "France", "FR Retail", null))
)
RETURN IF(ISBLANK(_value),0,_value)

 

If you have any ideas, please let me know, I will appreciate your help. 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Assume first date filter is working

 

M2 =
var _date = FIRSTDATE(Table[Creation Date])
var _value = CALCULATE(DISTINCTCOUNT(Table[Product Number]),filter( Table[Creation Date]=_date && ((Table[Country] = "Denmark" && Table[Sales Channel] = "DK Trade") || (Table[Country] = "France" && Table[Sales Channel] = "FR Retail"))
))
RETURN IF(ISBLANK(_value),0,_value)

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

View solution in original post

5 REPLIES 5
Fowmy
Super User
Super User

@Anonymous 

Try this way:

M2 = 
var _country = SELECTEDVALUE(Table[Country])
var _date = FIRSTDATE(Table[Creation Date])

var _value = CALCULATE(DISTINCTCOUNT(Table[Product Number]), Table[Creation Date]=_date,

IF ( _country = "Denmark", FILTER( Table, [Sales Channel]  = "DK Trade"),
IF ( _country = "France"), FILTER( Table, [Sales Channel]  = "FR Retail")))


RETURN IF(ISBLANK(_value),0,_value)

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

amitchandak
Super User
Super User

@Anonymous , Assume first date filter is working

 

M2 =
var _date = FIRSTDATE(Table[Creation Date])
var _value = CALCULATE(DISTINCTCOUNT(Table[Product Number]),filter( Table[Creation Date]=_date && ((Table[Country] = "Denmark" && Table[Sales Channel] = "DK Trade") || (Table[Country] = "France" && Table[Sales Channel] = "FR Retail"))
))
RETURN IF(ISBLANK(_value),0,_value)

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
Anonymous
Not applicable

Oh it seems to work like that! Thank you so much.

AllisonKennedy
Super User
Super User

Try using conditions and, or && ||

M2 =
var _date = FIRSTDATE(Table[Creation Date])
var _value = CALCULATE(DISTINCTCOUNT(Table[Product Number]), Table[Creation Date]=_date,
(Table[Sales Channel] = "DK Trade" && Table[Country] = "Denmark") ||
Table[Country] = "France" && Table[Sales Channel] = "FR Retail"))
)
RETURN IF(ISBLANK(_value),0,_value)

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Anonymous
Not applicable

When I did it as you said I got the error message:

 

Adnotacja 2020-09-07 114732.png

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.