Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Richard_Halsall
Helper IV
Helper IV

Adding DAX Variables to a table in a measure to create a count

Hi, I have been struggling with this DAX

 

I have 2 tables

Technician which has name & job role (this job role has multiple roles seperated with a colon)

Job Role which is a disconnected table containing the unique job roles

 

The disconnected table Job Role is used as a slicer, and I have the measure below which flags if a technician name has the selected slicer job role/s in their job role field

 

RoleCountRHTest =

VAR _a =
    SELECTCOLUMNS ( 'Technician Roles', "Slicer", [Technician Role] )
VAR _b =
    ADDCOLUMNS (
        _a,
        "Count",
            SWITCH (
                TRUE (),
                ISBLANK ( MAX ( 'DimContractor'[Job_Title__c] ) )
                    && [Slicer] = "No Role", 1,
                MAX ( 'DimContractor'[Job_Title__c] ) <> BLANK ()
                    && CONTAINSSTRING ( MAX ( 'DimContractor'[Job_Title__c] ), [Slicer] ), 1
            )
    )
RETURN
    IF (
        SUMX ( _b, [Count] )>=1
            || NOT ( ISFILTERED ( 'Technician Roles'[Technician Role] ) ),
        1,
        0
    )
 
This works fine in a table visual with the technician name and measure
Richard_Halsall_0-1705065698774.png

 

What I really need now is the measure above to be amended to calculate a count of those technicians where the RoleCountRHTest = 1 so I can show this in a card visual which will show the total number of technicians with the job roles selected in the disconnected slicer
 
Any help much appreciated. Thanks
1 ACCEPTED SOLUTION

you can with power query transfom the first table from : 

Daniel29195_0-1705069070950.png

 

to 

 

 

Daniel29195_1-1705069078513.png

 

View solution in original post

4 REPLIES 4
Daniel29195
Super User
Super User

why dont you expand the first table on rows, and then you can link table 2 to table 1  as  1-many relationship 

 

on job . 

 

wouldnt it ease your work ? 

Hi that wouldn't be possible Technician table has structure below:

Technician NameJob Role
DaveBlade Tech 1;Rope Tech 3
JohnBlade Tech 3

 

Disconnected table Job Role has structure below:

Job Role
Blade Tech 1
Blade Tech 3
Rope Tech 3

you can with power query transfom the first table from : 

Daniel29195_0-1705069070950.png

 

to 

 

 

Daniel29195_1-1705069078513.png

 

Thanks although that is a solution I would like to resolve in DAX rather than creating another table in the model, the model has far more breadth than the 2 tables I have cited in the example

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.