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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
JRA21_13_19_25
Frequent Visitor

Calculating unique values by month in DAX

HELLO,

 

I want to create a DAX formula that will calculate the total UNIQUE products by Month and Availabilty using the table below.

 

JRA21_13_19_25_0-1635446951470.png

 

So one formula will calculate total unique products for Online and this should give a value of 5 and for Instore it should give a value of 6.

 

I started by using the CALCULATE Function below but I don't know how to factor in finding the unique products by month:

 

Total Unique Products for Online = CALCULATE(DISTINCTCOUNT(Products[Product ID]),Products[Availability]="Online",

 

Please can someone kindly help me out with this.

 

Thanks in Advance!

 

 

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@JRA21_13_19_25 Try:

Measure = 
  VAR __Table = SELECTCOLUMNS('Table',"Month",[Month],"Product ID",[Product ID],"Availability",[Availability])
RETURN
  COUNTROWS(DISTINCT(__Table))

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
AlexisOlson
Super User
Super User

This seems like a good situation for SUMMARIZE.

 

Measure1 =
COUNTROWS (
    SUMMARIZE ( Table1, Table1[Month], Table1[Product ID], Table1[Availability] )
)
JRA21_13_19_25
Frequent Visitor

@Greg_Deckler  THANK YOU SO MUCH GREG!!! IT WORKED😁😃

Greg_Deckler
Super User
Super User

@JRA21_13_19_25 Try:

Measure = 
  VAR __Table = SELECTCOLUMNS('Table',"Month",[Month],"Product ID",[Product ID],"Availability",[Availability])
RETURN
  COUNTROWS(DISTINCT(__Table))

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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