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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
OlegV
Helper III
Helper III

Need to write a measure to use in a card visual

Hello,

I wrote a measure 'GetJob', which gets values from another table. It works.

 

But I am stuck at counting distinct values based on this measure to use it in the card visual. I can use only a measure, I cannot create additional calculated tables, columns or create a relationship.

 

Could you please help me. I've attached a sample pbi file, please download it from my onedrive

Sample


1 ACCEPTED SOLUTION

@OlegV 

 

GetJob = 

var ds = 
ADDCOLUMNS(
    FILTER(
    SalesOrders,
    NOT ISBLANK('SalesOrders'[StockCode]) &&
    NOT 'SalesOrders'[StockCode] = "    " &&
    'SalesOrders'[Quantity]<>0 &&
    'SalesOrders'[Status] in {"1","2","4"}
    ),
    
    "c" , 
    var c = SalesOrders[Company]
    var s = SalesOrders[SalesOrder]
    var so = SalesOrders[SalesOrderLine]
    return
    CALCULATE(
        DISTINCTCOUNT(WIPjobs[Job]),
        'WIPjobs'[Company]= c,
    'WIPjobs'[SalesOrder]= s,
    'WIPjobs'[SalesOrderLine]=so
    )
)

return SUMX(ds, [c])

    

 

 

this code should work . 

the output =  3  . 

 

 

If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution
It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠

View solution in original post

4 REPLIES 4
Daniel29195
Super User
Super User

@OlegV 

output 

Daniel29195_1-1709761472555.png

 

 

steps : 

create following columns in each table : 

 in salesorders : 

link = SalesOrders[SalesOrder] & "|" & SalesOrders[SalesOrderLine]
 
in WIPjobs
link = WIPjobs[SalesOrder] & "|" & WIPjobs[SalesOrderLine]
 
create a link between the 2 tables : 
Daniel29195_2-1709761567776.png

 

 

now create this measure for the card : 

 

 

GetJob = 

var ds = 
ADDCOLUMNS(
    VALUES(SalesOrders[SalesOrder]),
    "c", 
    CALCULATE(
        DISTINCTCOUNT('WIPjobs'[Job])
    )
)

 

 

 

and for the table : 

 

 

GetJob  new = 

var ds = 
ADDCOLUMNS(
    VALUES(SalesOrders[SalesOrder]),
    "c", 
    CALCULATE(
        MAX('WIPjobs'[Job])
    )
)

return CONCATENATEX(ds,[c])

 

 

 

 

let me know if this helps ./

 

 

If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution
It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠:

@Daniel29195 
thank you for a reply, but 
firstly, I cannot create additional tables, columns or create relationships. I need to achieve the result using a measure only.
secondly, there should be 3 unique Jobs, not 5. Because SalesOrder "C" is filtered out.

@OlegV 

 

GetJob = 

var ds = 
ADDCOLUMNS(
    FILTER(
    SalesOrders,
    NOT ISBLANK('SalesOrders'[StockCode]) &&
    NOT 'SalesOrders'[StockCode] = "    " &&
    'SalesOrders'[Quantity]<>0 &&
    'SalesOrders'[Status] in {"1","2","4"}
    ),
    
    "c" , 
    var c = SalesOrders[Company]
    var s = SalesOrders[SalesOrder]
    var so = SalesOrders[SalesOrderLine]
    return
    CALCULATE(
        DISTINCTCOUNT(WIPjobs[Job]),
        'WIPjobs'[Company]= c,
    'WIPjobs'[SalesOrder]= s,
    'WIPjobs'[SalesOrderLine]=so
    )
)

return SUMX(ds, [c])

    

 

 

this code should work . 

the output =  3  . 

 

 

If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution
It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠

Wow, it's worked!

 

I would ve never come up with this solution and did not find any hint also.

 

Thank you! Will study your code.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors