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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
DataAnalystSH
New Member

Calculation at line level in PBI using direct query

Hello all wise heads! 😎

 

I am struggling with calculation at line level using direct query to dataset.

I need to calculate how many "Orders" produce only "Services (TDS)". 

I have following table in my report with this structure of data, contains "Order", "Order Line Number", "Category":

 

Order         Order LineNr  Category

SO341TDG
SO342TDG
SO343TDG
SO344TDG
SO781TDS
SO782TDS
SO871TDG
SO872TDG
SO873TDS
SO874TDS
SO875TDG
SO876TDS

 

I need to calculate measure, which shows me only "Order" which contain ONLY "TDS"

It means that if the one "Order" with multiple "Order Line Nr." has in column "Category" "TDG" and "TDS", I am not counting it.

If if the one "Order" with multiple "Order Line Nr." has in column "Category" only "TDS", no combination or "TDG", then I am counting it.

 

I try to use function EARLIER in measure but it doesn´t works (probably there is limitation of using direct query).

 

Could you please help me with that?🤔

Thank you very much!

2 REPLIES 2
DataAnalystSH
New Member

Hi @amitchandak 

I tried your measure and it shows me an error 

DataAnalystSH_0-1661244290849.png

I also try something like this:

= IF (MAXX (FILTER ( data,data[Sales Voucher Number] = EARLIER ( data[Sales Voucher Number] ) ),
( data[POG Level 1])) = "TDS%",
"No",
"Yes")
it also doesn´t work, because it assigned only YES to all records..
 
but thank you for your answer!
amitchandak
Super User
Super User

@DataAnalystSH , try a new measure

 


new measure =
var _cnt = countx(allselected(Table), [Order] = max(Table[Order]) && Table[Category] <> "TDS")
return
calculate(count(Table[Order LineNr]), filter(Table, isblank(_cnt)))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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