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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Serdet
Post Patron
Post Patron

If jobs match, sum cost types

Hi All,

 

I have a dataset similar to the below

 

JobUnit Rate or Day WorkCost
1Unit Rate£10
2Day Work£50
1Day Work£100
4Unit Rate£1000

 

I want to create a two measures measures

 

Measure 1 - checks to see if the same job has unit rate and day work cost allocated then creates a count of how many times this happens

 

Measure 2 - checks to see if the same job has unit rate and day work cost allocated then sums up the 'Cost' for how many times this happens 

The above example would return the below outputsl

 

Measure 1 = 1

Measure 2 = £110

 

Please can someone help me with the DAX?

1 ACCEPTED SOLUTION

@Serdet , try this:-

SUMX (
    FILTER (
        SUMMARIZE (
            Employee,
            Employee[Employee Name],
            "_1",
                COUNTX (
                    FILTER ( Employee, Employee[Day Work Indicator] = "Unit rate" ),
                    [Job]
                ),
            "_2",
                COUNTX (
                    FILTER ( Employee, Employee[Day Work Indicator] = " Day work" ),
                    [Job]
                ),
            "UP Cost", SUM ( Employee[UP Cost] )
        ),
        NOT ( ISBLANK ( _1 ) )
            && NOT ( ISBLANK ( _2 ) )
                && [_1] > 0
                && [_2] > 0
    ),
    [UP Cost]
)

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

8 REPLIES 8
v-yalanwu-msft
Community Support
Community Support

Hi, @Serdet ;

Try it.

Measure 1 = 
var _a=SUMMARIZE( FILTER(ALL('Table'),[Unit Rate or Day Work]="Unit rate"),[Job])
var _b=SUMMARIZE( FILTER(ALL('Table'),[Unit Rate or Day Work]="Day work"),[Job])
var  _c=DISTINCT( INTERSECT(_a,_b))
return COUNTROWS(_c)
Measure 2 = 
var _a=SUMMARIZE( FILTER(ALL('Table'),[Unit Rate or Day Work]="Unit rate"),[Job])
var _b=SUMMARIZE( FILTER(ALL('Table'),[Unit Rate or Day Work]="Day work"),[Job])
return  SUMX(FILTER(ALL('Table'),[Job] in INTERSECT(_a,_b)),[Cost])

The final output is shown below:

vyalanwumsft_0-1643002366135.png


Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Serdet ,The information you have provided is not making the problem clear to me. Can you please explain with an example.

Appreciate your Kudos.

Thanks for the reponse.

 

Please see below example

 

Measure 1 - If jobs are the same and have unit rate and day work, make a count

                    In the above example, job 1 has a row for unit rate and day work, this would count as 1

 

Measure 2 - If jobs are the same and have unit rate and day work, sum the cost

                    In the above example, job 1 has a row for unit rate and day work, this would sum up the cost                         for each of these, totaling to £110

 

Hope this makes sense.

 

 

@Serdet , Try two measures like

 

countx(filter(summarize(Table, Table[Name], "_1", countx(filter(Table, Table[ Unit Rate or Day Work] = "Unit rate"),[Job])
, "_2", countx(filter(Table, Table[ Unit Rate or Day Work] = " Day work"),[Job]) )
not(isblank(_1)) && not(isblank(_2)) && [_1] >0 && [_2]>0), [Name] )

 

 

Sumx(filter(summarize(Table, Table[Name], "_1", countx(filter(Table, Table[ Unit Rate or Day Work] = "Unit rate"),[Job])
, "_2", countx(filter(Table, Table[ Unit Rate or Day Work] = " Day work"),[Job]), "_Sum", sum(Table[Cost]) )
not(isblank(_1)) && not(isblank(_2)) && [_1] >0 && [_2]>0), [Cost] )

Hi, 

 

Thanks for the clarification, the CountX expression works perfeclty but I am having troubles with the Sumx expression. The DAX is not allowing me to put the last [Cost] into the expression.

 

Please see below.

 

Serdet_0-1643010867399.png

 

@Serdet , You have some missing closing brackets. Please use it like below:-

SUMX (
    FILTER (
        SUMMARIZE (
            Employee,
            Employee[Employee Name],
            "_1",
                COUNTX (
                    FILTER ( Employee, Employee[Day Work Indicator] = "Unit rate" ),
                    [Job]
                ),
            "_2",
                COUNTX (
                    FILTER ( Employee, Employee[Day Work Indicator] = " Day work" ),
                    [Job]
                ),
            "_Sum", SUM ( Employee[UP Cost] )
        ),
        NOT ( ISBLANK ( _1 ) )
            && NOT ( ISBLANK ( _2 ) )
                && [_1] > 0
                && [_2] > 0
    ),
    [UP Cost]
)

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Hi,

 

I am still being told [UP Cost] cannot be used in this expression. 

Serdet_0-1643014639266.png

 

@Serdet , try this:-

SUMX (
    FILTER (
        SUMMARIZE (
            Employee,
            Employee[Employee Name],
            "_1",
                COUNTX (
                    FILTER ( Employee, Employee[Day Work Indicator] = "Unit rate" ),
                    [Job]
                ),
            "_2",
                COUNTX (
                    FILTER ( Employee, Employee[Day Work Indicator] = " Day work" ),
                    [Job]
                ),
            "UP Cost", SUM ( Employee[UP Cost] )
        ),
        NOT ( ISBLANK ( _1 ) )
            && NOT ( ISBLANK ( _2 ) )
                && [_1] > 0
                && [_2] > 0
    ),
    [UP Cost]
)

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.