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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
transform99
Resolver I
Resolver I

SumX for Product Value based on Max Date

I have a warehouse report that shows stock levels.

 

I have the following formula that is aiming to return 1 of 2 values:

If the [Reporting Date] is filtered then show the [product value] based on the [Reporting Date], else show the [product value] based on the most recent [Reporting Date].

 

 

WHS Value = 
VAR _ReportDate =
    MAX ( 'Table1'[Reporting Date] )

RETURN
    IF (
        ISFILTERED ( 'Table1'[Reporting Date] ) = FALSE (),
        SUMX (
            FILTER ( 'Table1', _ReportDate = 'Table 1'[Reporting Date] ),
            'Table1'[Product Value]
        ),
        SUM ( 'Table1'[Product Value] )
    )

 

 

My issue is that if there is no stock in the warehouse it's a null value, and the formula displayed is showing historic data from older snapshots.

How can I amend this formula so that where products have no stock (and the report is null) - it excludes them from the formula when no report date is selected?

 

transform99_0-1673921052954.png

 

7 REPLIES 7
Ashish_Mathur
Super User
Super User

Hi,

Share some data (in a format that can be pasted in an MS Excel file), explain the question and show the expected result. in a simple Table format.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@Ashish_Mathur below is a pivot table summary with the current result vs expected result. I've also included a raw example which can be pivoted.

 

This is essentially an exercise in handling nulls/blanks where stock is not present at certain times.

 

 SOH  Current ResultExpected Result
Product ID21/11/2022

19/12/2022

16/01/2023  
100151221814 140
1001577522 20
100235673890  38900
1002480644 40
100248811  10
100274914  40
100021311313131313
100021863034151515
1000218999333
100021901113141414
100021952735181818
100021961112131313

 

Raw Extract:

Product NumberUnit Of MeasureSOHReport Run Date
10015122EA1821/11/2022
10015775EA221/11/2022
10023567MT89021/11/2022
10023567MT200021/11/2022
10023567MT100021/11/2022
10024806EA421/11/2022
10027491EA421/11/2022
10002189EA321/11/2022
10002189EA521/11/2022
10002189EA121/11/2022
10002190EA621/11/2022
10002190EA221/11/2022
10002190EA321/11/2022
10015122EA1419/12/2022
10015775EA219/12/2022
10024806EA419/12/2022
10002189EA419/12/2022
10002189EA419/12/2022
10002189EA119/12/2022
10002190EA819/12/2022
10002190EA319/12/2022
10002190EA219/12/2022
10002189EA216/01/2023
10002189EA116/01/2023
10002190EA816/01/2023
10002190EA416/01/2023
10002190EA216/01/2023

Hi,

You may download my PBI fle from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish,

Sorry it's taken me so long to get back to this but I couldn't get this to work.

 

I have 2 tables that follow the exact same path as the data I have provided to you, but in 1 table it has a Subcontractor ID instead of a Product ID and it was still showing values that were historic from old reporting periods.

 

The issue I was facing was that regardless of the MaxDate that was coming through from [Report Run Date] or Calendar[Date] in your example - When applying the measure it was assessing it individually per product ID / Subcontractor ID.

 

The solution I found was to use a calculated column:

WHS MaxDate = Max([Report Run Date])

 

The following worked:

WHS Value = 
    IF (
        ISFILTERED ( 'Table1'[Reporting Date] ) = FALSE (),
        SUMX (
            FILTER ( 'Table1', [WHS MaxDate] = 'Table 1'[Reporting Date] ),
            'Table1'[Product Value]
        ),
        SUM ( 'Table1'[Product Value] )
    )

You might as well start a new thread.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Not required, solution found - more a follow up to say thankyou for your input because it helped me find my solution.

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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