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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Count Distint batches with filters

 

Hi,

I am pretty new to DAX and Power BI. I am trying to calculate the number of Item batches in stock per day for a table like below:

 

InventoryTransaction

ItemNumber

Item Batch

StatusDate

Quantity

5637151470

10001332

0000000007

 09 February 2021

 -56

5637151472

10001332

0000000007

 09 February 2021

 -56

5637151471

10001332

0000000007

 09 February 2021

  56

5637151473

10001332

0000000007

 09 February 2021

  56

5637151582

10001332

0000000008

 11 February 2021

  56

5637151583

10001332

0000000009

 11 February 2021

  56

5637150642

10001332

0000000007

 16 March 2021

  56

5637151351

10001332

0000000007

 1 May 2021

 -56

5637151352

10001332

0000000008

 1 May 2021

 -56

5637151353

10001332

0000000009

 1 May 2021

 -56

 

on 09/02/2021 should be 0 as the qty sum for that day is zero (and the same for all periods till 11/02/21)

on 11/02/2021 should be 2 (and the same for all periods till 16/02/21)

on 16/03/2021 should be 3 (the same for all periods till 01/05/2021)

on 01/05/2021 should be 0

 

I have tried below but is not good enough:

 

Count Distint Batches =

VAR _currdatekey = MAX ('dwh view_DateRelative'[DayDate])

RETURN

CALCULATE(

DISTINCTCOUNT ('dwh view_fact_InventoryTransaction'[ItemBatchKey]),

FILTER(

ALLSELECTED ('dwh view_DateRelative'[DayDate]),

ISONORAFTER ('dwh view_DateRelative'[DayDate],_currdatekey, DESC)

))

 

Can you help please?

Regards

2 REPLIES 2
Anonymous
Not applicable

Thank you AmitChandak,

I have tried several things but I cannot get it to work properly, due to my limited knowledge of DAX.

I would really appreciate if could you be more specific, please?

amitchandak
Super User
Super User

@Anonymous , Try a measure like

 

countx(values(Table[StatusDate]), calculate(Sum(Table[Quantity])))

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
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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