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
naveenwills
Frequent Visitor

Occurrence per week which should be filterable by month

With a Master table as below

naveenwills_0-1710456223983.png

 

How to caculate how many times a cardholder has appeared in a week using DAX?

for example I want the end result to look like below and this should be filterable by month, if I change to January the week numbers should change with it as well. I have a seperate calander table. 

naveenwills_1-1710456441285.png

 

Another important thing is the calculation should consider only one entry per day that means if the cardhoder goes out and in several times in a day, it should only calculate once per day. So the occurance can only be once, twice, trice, 4 times, 5 times, 6 times or all 7 days. 

 

I have managed to do this using power query grouping. However I want to be able to do this on the master table in DAX.

 

any help is greatly appreciated.

Thanks

 

1 ACCEPTED SOLUTION

Hi @naveenwills ,

 

In the Power Query, select the Transform tab and click Group By to make the following settings.

vhuijieymsft_0-1710726106138.png

vhuijieymsft_1-1710726106140.png

 

This will calculate the number of occurrences per week for each cardholder.

 

Click Close and Apply to return to Power BI Desktop.

 

Select the Matrix visualization.

 

Drag Week of Year to the Rows field.

 

Drag Cardholder Name to the Column field.

 

Drag Count to the Values field and set the aggregation to "Count".

vhuijieymsft_2-1710726153770.png

 

The final visual is shown below:

vhuijieymsft_3-1710726153771.png

 

If you have any other questions please feel free to contact me.

 

The pbix file is attached.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

View solution in original post

4 REPLIES 4
naveenwills
Frequent Visitor

Thanks @v-huijiey-msft , 

That doesnt work as it sets 0 to a person who has only 1 occurrence. 

 

See sample data 

Entry Date/Time       Location    Cardholder Name Email Address     Week of Year

08/01/2024 08:02Loc1Mr D Duckd.duck@gomail.com2
08/01/2024 14:21Loc1Mr D Duckd.duck@gomail.com2
09/01/2024 08:56Loc1Mr D Duckd.duck@gomail.com2
11/01/2024 08:13Loc2Mr D Duckd.duck@gomail.com2
12/01/2024 08:31Loc1Mr D Duckd.duck@gomail.com2
15/01/2024 08:08Loc1Mr D Duckd.duck@gomail.com3
15/01/2024 09:43Loc1Mr J Bloggsjbloggs@gomail.com3
16/01/2024 08:24Loc1Mr D Duckd.duck@gomail.com3
16/01/2024 10:27Loc2Mr D Duckd.duck@gomail.com3
17/01/2024 14:17Loc2Mr D Duckd.duck@gomail.com3
18/01/2024 12:40Loc1Mr D Duckd.duck@gomail.com3
19/01/2024 08:07Loc1Mr D Duckd.duck@gomail.com3
22/01/2024 08:35Loc2Mr D Duckd.duck@gomail.com4
22/01/2024 11:59Loc1Mr D Duckd.duck@gomail.com4
23/01/2024 08:16Loc1Mr D Duckd.duck@gomail.com4
25/01/2024 00:00Loc1Mr D Duckd.duck@gomail.com4
26/01/2024 08:08Loc1Mr D Duckd.duck@gomail.com4

 

Result I want to see

 Mr D DuckMr J Bloggs
Week 24 
Week 351
Week 44 

 

Hi @naveenwills ,

 

In the Power Query, select the Transform tab and click Group By to make the following settings.

vhuijieymsft_0-1710726106138.png

vhuijieymsft_1-1710726106140.png

 

This will calculate the number of occurrences per week for each cardholder.

 

Click Close and Apply to return to Power BI Desktop.

 

Select the Matrix visualization.

 

Drag Week of Year to the Rows field.

 

Drag Cardholder Name to the Column field.

 

Drag Count to the Values field and set the aggregation to "Count".

vhuijieymsft_2-1710726153770.png

 

The final visual is shown below:

vhuijieymsft_3-1710726153771.png

 

If you have any other questions please feel free to contact me.

 

The pbix file is attached.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

Thanks for the reply @v-huijiey-msft 

Apologies for the late reply as I was away sick. I have already done this in my current solution. The problem I have with this is other columns of information I want to use gets grouped / stripped out.  

Those columns are really important for relationships with other tables and thats why was wondering if there is other way to achieve this solution. 

One of the other visual I want to use with all this also looks like this

naveenwills_0-1711375559746.png

 

Thanks

v-huijiey-msft
Community Support
Community Support

Hi @naveenwills ,

 

Please try:

 

Create a calculated column in your master table that flags the first entry of each day.

First Entry Flag = 
VAR CurrentDate = Master[Date]
VAR CurrentLocation = Master[Location]
RETURN IF (
    MINX (
        FILTER (
            Master,
            Master[Date] = CurrentDate && Master[Location] = CurrentLocation
        ),
        Master[Entry Time]
    ) = Master[Entry Time],
    1,
    0
)

 

Create a measure to count the number of unique days in a week that have an entry.

Weekly Occurrences = 
CALCULATE (
    DISTINCTCOUNT (Master[Date]),
    Master[First Entry Flag] = 1
)

 

I would appreciate it if you could provide me with sample data for testing, not in the form of screenshots, please remove any sensitive data in advance.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

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.