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
C-G-Davidson
Frequent Visitor

Count Occurrences of future dates based on single date column for site locations

Looking for some help on counting dates in a column which will allow filtering per location.

If we imagine a fictional warehouse table where id is a single order.

 

IdReceivedProcessedCheckedDispatched
12020-01-01   2020-01-01   2020-01-01   2020-01-01   
22020-01-012020-01-012020-01-022020-01-03
32020-01-022020-01-022020-01-022020-01-10
42020-01-022020-01-022020-01-022020-01-02

 

I have linked the received field to a column of single dates in my calendar table.

What I am looking for is to list out each date from the calendar and count the number of dates for each category that match so e.g. for the date 2020-01-01
We recieved 2 orders

We processed 2 orders

We checked 1 order

We dispatched 1 order

 

For the table of orders above it would result in

 

DateReceivedProcessedCheckedDispatched
2020-01-01    2    2    1    1
2020-01-02    2    2    3    1
2020-01-03    0    0    0    1
2020-01-10    0    0    0    1

 

I thought I had it with this code where I added a count of dates to the calendar table in a calculated column. One column for each count of received, processed, checked, dispatched.

'checked one below'

checked_orders = CALCULATE(COUNTROWS(orders), FILTER(orders, orders[checked] = 'Calendar'[Date]))

 

Terribly inneficient I know but I am trying anything. Anyway the method doesn't seem to be the correct way as it won't allow filtering on locations. 

 

If you imagine the orders table is filled with orders from 10 locations identified by a location_id 1-10 . If the user selects a specific location e.g. location 2 then the results table should only list the count of recieved, processed,checked,dispatched for location 2.

 

For help, it is safe to assume that every day of the year will have at least 1 order per day.

 

Sorry if the description seems strange, the actual problem relates to a pharmacy company with many branches so tried to relate it to an easier to explain problem.

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@C-G-Davidson 

You need to create four measures and no need to link the date table with the calendar table if you arent not using it for any other purpose.

 

Received Count = 
COUNTROWS(
    FILTER(
        Table10,
        Table10[Received] = MAX('Table'[Date])
    )
)
Processed Count = 
COUNTROWS(
    FILTER(
        Table10,
        Table10[Processed] = MAX('Table'[Date])
    )
)
Checked Count = 
COUNTROWS(
    FILTER(
        Table10,
        Table10[Checked] = MAX('Table'[Date])
    )
)
Dispatched Count = 
COUNTROWS(
    FILTER(
        Table10,
        Table10[Dispatched] = MAX('Table'[Date])
    )
)

 

 

________________________

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

View solution in original post

1 REPLY 1
Fowmy
Super User
Super User

@C-G-Davidson 

You need to create four measures and no need to link the date table with the calendar table if you arent not using it for any other purpose.

 

Received Count = 
COUNTROWS(
    FILTER(
        Table10,
        Table10[Received] = MAX('Table'[Date])
    )
)
Processed Count = 
COUNTROWS(
    FILTER(
        Table10,
        Table10[Processed] = MAX('Table'[Date])
    )
)
Checked Count = 
COUNTROWS(
    FILTER(
        Table10,
        Table10[Checked] = MAX('Table'[Date])
    )
)
Dispatched Count = 
COUNTROWS(
    FILTER(
        Table10,
        Table10[Dispatched] = MAX('Table'[Date])
    )
)

 

 

________________________

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

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