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

Need help calculating occurrences using a date slicer and occurrence number

Hi 

I have a table  which the picture below show the basic structure. 

PresentationID   CustomerID    Date

----------------------------------------------

1                          A                     3/7/2020

2                          B                     7/7/2020

3                          C                     9/8/2020

4                          C                     15/8/2020

5                          B                     29/8/2020

6                          D                     31/8/2020

I need a measure that calculates me the number of customer presentations between a date range and filtered by a number of presentation slicer. Foexample; if date rance is from 3/7/2020 to 31/8/2020 and presentation count slicer set to 1, just patients A and D but presentation count slicer set to  2 , patients B and C should be displayed.  If date rance is from 1/8/2020 to 31/8/2020 and presentation count slicer set to 1, just patient D but presentation count slicer set to  2 , just patient C should be displayed.  

Can anyone help with the measure please? Thanks.

2 ACCEPTED SOLUTIONS
jdbuchanan71
Super User
Super User

Hello @ilky

You can create a table to contain the Layout Count selection in this way.

Modeling > New Table:

Presentation Count = 
DATATABLE(
    "Number of Presentations",INTEGER,
    {
        {1},{2},{3},{4},{5},{6},{7},{8},{9},{10}
    }
)

Next, a measure to count the number of preseations.

Presentation Count = COUNTROWS('DataTable')

And finally a measure to apply the selection to the count to simply return the matching rows.

Filtered Presentation Count =
CALCULATE (
    [Presentation Count],
    FILTER (
        VALUES ( 'DataTable'[CustomerID] ),
        [Presentation Count]
            IN ( VALUES ( 'Presentation Count'[Number of Presentations] ) )
    )
)

I've attached my sample file for you to look at.

View solution in original post

@Anonymous , you have to remove the arrival date.

 

or use a measure with

calculate(count(Table[Date]), allexcept(Table, Table[CustomerID]))

try liek

measure =
var _max = selectedvalue(names[first Name])
if(calculate(count(Table[Date]), allexcept(Table, Table[CustomerID])) =_max, 1, blank())

View solution in original post

8 REPLIES 8
jdbuchanan71
Super User
Super User

Hello @ilky

You can create a table to contain the Layout Count selection in this way.

Modeling > New Table:

Presentation Count = 
DATATABLE(
    "Number of Presentations",INTEGER,
    {
        {1},{2},{3},{4},{5},{6},{7},{8},{9},{10}
    }
)

Next, a measure to count the number of preseations.

Presentation Count = COUNTROWS('DataTable')

And finally a measure to apply the selection to the count to simply return the matching rows.

Filtered Presentation Count =
CALCULATE (
    [Presentation Count],
    FILTER (
        VALUES ( 'DataTable'[CustomerID] ),
        [Presentation Count]
            IN ( VALUES ( 'Presentation Count'[Number of Presentations] ) )
    )
)

I've attached my sample file for you to look at.

Anonymous
Not applicable

Hi @jdbuchanan71

I created the Presentation Count using GenerateSeries() function and your answer solved my issue. Many thanks 🙂

Ilky

Anonymous
Not applicable

Thank you @jdbuchanan , I cannot open the sample report as it is not compatible with my PBI version but I will try your suggestions in my report.

Regards

Ilky

amitchandak
Super User
Super User

@Anonymous , Hope you had what if a measure to select values 1,2,3 

 

Then have this measure along with customer in visual

measure =
var _cnt = selectedvalue(Param[count])
return
Countx(filter(summarize(Table,Table[CustomerID], "_1", count(Table[Date])),[_1]>=_cnt),[CustomerID])

 

https://docs.microsoft.com/en-us/power-bi/desktop-what-if

Anonymous
Not applicable

Hi @amitchandak 

Thank you for responding to my query. I am still new to a lot of conceps in Power BI. I have done your suggesttion, however here is the result :

ilky_0-1601862684158.png

And the measure is :

ilky_1-1601862725973.png

I don't think this is giving what I am after though. If the No of Presentation is set to 3, I should only see Customers measure = 3 within the date range. The measure shows 1 , why?

thanks again for your help 🙂

Ilky

@Anonymous , you have to remove the arrival date.

 

or use a measure with

calculate(count(Table[Date]), allexcept(Table, Table[CustomerID]))

try liek

measure =
var _max = selectedvalue(names[first Name])
if(calculate(count(Table[Date]), allexcept(Table, Table[CustomerID])) =_max, 1, blank())

Anonymous
Not applicable

 

Hi @amitchandak , @jdbuchanan71 

Oh ok, thank you so much. 

Is there anyway I can make the MAX value of number of presentations slicer value dynamicly changed based on the date range selected? 

Ilky

Anonymous
Not applicable

Hi @amitchandak , @jdbuchanan71 

One more question, I am trying to count the occurence of a customer presentation within the last 7 days and I am getting and error and cannot understand why.

ilky_0-1601881362407.png

Thanks heaps, you have been wonderful !

Ilky

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.