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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
jimrosser
Helper III
Helper III

Measrue with If statement based on Count

I've got a table that I only want the amount not sum of total for qty on hand for day 7 of the week.  The measure below calculates correctly unless there are multiple entries for the same day of that week.   is there a way to modify the formula so that it will count the occurences and if more than 1 divide by the count number?  If i replace Sum with Count i can see that in week 28 it returns 2 while all the other weeks are only returning 1.

 

RINVT Running Total in DAX = CALCULATE(SUM(store_invt[ty_on_hand_qty]),
    FILTER(
        ALL(calendar_dim),
        'calendar_dim'[wk_day_nbr] = 7),
        VALUES ( 'calendar_dim'[wk_nbr] )
)
1 ACCEPTED SOLUTION
v-jialongy-msft
Community Support
Community Support

Hi @jimrosser 

Please try the following Dax:

RINVT Running Total in DAX = 
VAR _Total = CALCULATE(SUM(store_invt[ty_on_hand_qty]),
    FILTER(
        ALL(calendar_dim),
        'calendar_dim'[wk_day_nbr] = 7),
        VALUES ( 'calendar_dim'[wk_nbr] )
)
RETURN
IF(store_invt[COUNT]=1,_Total,_Total/store_invt[COUNT])

 

If the formula doesn't solve your problem, please provide sample data that fully covers your issue(pbix file or table) and the expected outcome based on the sample data you provided.

 

 

 

 

 

 

 

 

Best Regards,

Jayleny

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-jialongy-msft
Community Support
Community Support

Hi @jimrosser 

Please try the following Dax:

RINVT Running Total in DAX = 
VAR _Total = CALCULATE(SUM(store_invt[ty_on_hand_qty]),
    FILTER(
        ALL(calendar_dim),
        'calendar_dim'[wk_day_nbr] = 7),
        VALUES ( 'calendar_dim'[wk_nbr] )
)
RETURN
IF(store_invt[COUNT]=1,_Total,_Total/store_invt[COUNT])

 

If the formula doesn't solve your problem, please provide sample data that fully covers your issue(pbix file or table) and the expected outcome based on the sample data you provided.

 

 

 

 

 

 

 

 

Best Regards,

Jayleny

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Ritaf1983
Super User
Super User

Hi @jimrosser 

Can you please share a pbix or some dummy data that keep the raw data structure with expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

 

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Rita - here's the table that I'm using.  Week 28 should be 111 not 222.  If the count in the last column is greater than 1 I'd like to divide in the measure by that number.

item_nbritem_namestore_nbrcal_yr_nmwk_nbrRunning Total in DAXRINVT Running Total in DAXCOUNT
123456BASIC ITEM1Year 202421 01
123456BASIC ITEM1Year 202422 01
123456BASIC ITEM1Year 202423 01
123456BASIC ITEM1Year 202424 2001
123456BASIC ITEM1Year 202425201801
123456BASIC ITEM1Year 202426241561
123456BASIC ITEM1Year 202427301261
123456BASIC ITEM1Year 202428152222

Helpful resources

Announcements
Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors