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
SriRed123
Regular Visitor

Summarise and count data if available on all days in Slicer date range

HI,

I am new to power BI and need help with below query.

I have a table with below data. The result should summarize the Data at product and get the count of distinct locations if the location present on all days selected in the slicer data range.

For Date range 1-DEC-19 to 1-DEC-19 result should be

A   3

B  3

For Date range 30-Nov-19 to 1-DEC-19:

A    2

B    1

For Date range 29-Nov-19 to 1-DEC-19:

A    1

B    0

Product

Location

Date

A

1

1-Dec-19

A

1

30-Nov-19

A

2

1-Dec-19

A

2

30-Nov-19

A

2

29-Nov-19

A

3

1-Dec-19

B

1

1-Dec-19

B

1

30-Nov-19

B

2

1-Dec-19

B

2

29-Nov-19

B

2

28-Nov-19

B

3

1-Dec-19

 

Sql query for producing similar result

SELECT Product, count(distinct Location) FROM (

SELECT Product,Location,count(*) cnt FROM #temp

WHERE Date between <SlicerStartDate> and <SlicerEndDate>

GROUP BY Product,Location

Having count(*) = (SELECT Datediff(Day,MAX(<SlicerEndDate>), MIN(<SlicerStartDate>)) + 1)) A

GROUP BY A.Product

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Probably something along the lines of:

 

Measure = 
VAR __count = COUNTX(DISTINCT('Table'[Date]),[Date])
VAR __table = SUMMARIZE('Table','Table'[Location],"Rows",COUNTROWS('Table'))
VAR __table1 = FILTER(__table,[Rows] = __count)
RETURN
COUNTX(__table1,[Location])

See attached.


@ 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

2 REPLIES 2
Greg_Deckler
Super User
Super User

Probably something along the lines of:

 

Measure = 
VAR __count = COUNTX(DISTINCT('Table'[Date]),[Date])
VAR __table = SUMMARIZE('Table','Table'[Location],"Rows",COUNTROWS('Table'))
VAR __table1 = FILTER(__table,[Rows] = __count)
RETURN
COUNTX(__table1,[Location])

See attached.


@ 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...

Many thanks. The measure is working exactly as per my requirement.

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.

Top Solution Authors