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

Dax Calculation

To find out how many times a Job ID appears in my Data set, I used the formula

COUNTROWS(FILTER('Engrs Timesheet', EARLIER('Engrs Timesheet'[Job ID],1) = ('Engrs Timesheet'[Job ID]))) in the column VISITCOUNT2

 

I further want to streamline my analysis to count only job numbers that appear multiple times on different days and (not on the same date)


So here is a sample of my Data

Femi10_0-1635962919739.png

 

I want to write a function that counts the number of times a Job number appears into the VisitCount2 column, but I only want it to count it as two if the job numbers are not on the same On-site date.

 

That is D0000178 should be counted as 3 rather than 4 because two of its elements have the same On-site date (11/10/2021) same as M00002062 which should be counted as 2 instead of 3 because two of its elements have same On-site date (26/10/2021)

 
Thank you all

1 ACCEPTED SOLUTION
smpa01
Super User
Super User

@Femi10  you can try this

Column =
CALCULATE (
    COUNTX (
        SUMMARIZE ( 'Table', 'Table'[ID], 'Table'[On Site] ),
        'Table'[On Site]
    ),
    ALLEXCEPT ( 'Table', 'Table'[ID] )
)

 

pbix is attached

 

smpa01_0-1635971847903.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

4 REPLIES 4
smpa01
Super User
Super User

@Femi10  you can try this

Column =
CALCULATE (
    COUNTX (
        SUMMARIZE ( 'Table', 'Table'[ID], 'Table'[On Site] ),
        'Table'[On Site]
    ),
    ALLEXCEPT ( 'Table', 'Table'[ID] )
)

 

pbix is attached

 

smpa01_0-1635971847903.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Femi10
Frequent Visitor

@smpa01 

It worked perfectly well

Thank you so much!!!

Femi10
Frequent Visitor

@smpa01 

Could you please share a brief explanation on how you came about this solution.

Thanks

@Femi10  sure.

 

If you dissect the code, it has three parts

Column = 
CALCULATE (
    COUNTX (
        SUMMARIZE ( 'Table', 'Table'[ID], 'Table'[On Site] ),
        'Table'[On Site]
    ),
    ALLEXCEPT ( 'Table', 'Table'[ID] )
)

the inner most part is SUMMARIZE, the immediate outer part is COUNTX and outer most part is Calculate with partition(ALLEXCEPT).

 

SUMMARIZE generates a distinct table with all unique combinations of ID and Site which looks like this

smpa01_0-1636034863384.png

COUNTX has an iterator  and if I pass on the following it generates this which is the total count of all the rows from that summarized table

smpa01_1-1636035045452.png

CALCULATE being the modifier, the partition by which the count needs to be performed can be mentioned and it gives the desired result.

smpa01_2-1636035190788.png

 

 

 

 

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

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