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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
ValeriaBreve
Post Partisan
Post Partisan

Helo with Dax formula for calculating requirement Independent from table column

Hello, 

I have a table as follows:

 

DateID & TextPack Type# Requirements per Pallet# Req CP3
8/11/20251A20 
8/11/20252A10 
8/11/20253A30 
8/11/20254B7010
8/12/20251A50 
8/12/20252A90 
8/12/20253A60 
8/12/20254B25050
8/13/20251A5 
8/13/20252A90 
8/13/20253A55 
8/13/20254B20050

 

# Req CP3 is what I need to calculate, and it is basically the total [# Requirements per Pallet] for Trade_Products[Pack Type]="B" for the selected date minus the sum of all [# Requirements per Pallet] for Trade_Products[Pack Type]="A" at the selected date.

I don't seem to be getting it right 😞

 

VAR SelectedDate = SELECTEDVALUE( Date_Table[Date] )


VAR PalletReq =
CALCULATE(
[# Requirements],
Trade_Products[ID & Text] = "4",
Date_Table[Date] = SelectedDate
)

 

//this should calculate the aggregate of all Product Types = "A" on the selected date

VAR FutsReq =
CALCULATE(
[# Requirements per Pallet],
Trade_Products[Pack Type] = "A",
Trade_Products[ID & Text] <> "4",
Date_Table[Date] = SelectedDate
)
RETURN
PalletReq - FutsReq

 

With this, I am getting a column that gives me the same numbers as per [# Requirements per Pallet], and not the aggregation I am looking for.

 

Can you help me understand which direction to take?

Thanks!

Kind regards

Valeria

 

 

 

1 ACCEPTED SOLUTION

@ValeriaBreve So that would be:

Measure = 
    VAR __Type = MAX( 'PackDimension'[Pack Type] )
    VAR __Date = MAX( 'DateDimension'[Date] )
    VAR __ATable = FILTER( ALL( 'Table' ), [Date] = __Date && [Pack Type] = "A" )
    VAR __Result = IF( __Type = "A", BLANK(), MAX( 'Table'[# Requirements per Pallet] ) - SUMX( __ATable, [# Requirements per Pallet] ) )
RETURN
    __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

8 REPLIES 8
johnt75
Super User
Super User

You can create a measure like

# Req CP3 = 
IF( SELECTEDVALUE( 'Table'[ID & Text] ) = 4,
	VAR PalletReq = 
	CALCULATE(
		SUM( 'Table'[# Requirements per Pallet] ),
		REMOVEFILTERS( 'Table' ),
		'Table'[ID & Text] = 4,
		VALUES( 'Date'[Date] )
	)
	VAR FutsReq = 
	CALCULATE(
		SUM( 'Table'[# Requirements per Pallet] ),
		REMOVEFILTERS( 'Table' ),
		'Table'[ID & Text] <> 4,
		'Pack Type'[Pack Type] = "A",
		VALUES( 'Date'[Date] )
	)
	RETURN PalletReq - FutsReq
)

See attached PBIX for reference.

@johnt75 Hi John, your solution also works beautifully! A pity I cannot accept 2 solutions, I already accepted Greg's as it came first, but thank you so much - I have learned a lot from your code!

Greg_Deckler
Community Champion
Community Champion

@ValeriaBreve Try:

Measure = 
    VAR __Type = MAX( 'Table'[Pack Type] )
    VAR __Date = MAX( 'Table'[Date] )
    VAR __ATable = FILTER( ALL( 'Table' ), [Date] = __Date && [Pack Type] = "A" )
    VAR __Result = IF( __Type = "A", BLANK(), MAX( 'Table'[# Requirements per Pallet] ) - SUMX( __ATable, [# Requirements per Pallet] ) )
RETURN
    __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler , thank you! however I have a date table for [Date] and another dimension table for [Pack Type" so when coming to Var _ATable I was not sure how to proceed as in this one everything is supposed to be on the same table (I have 2 dimensions and a fact table).

I ended up with something like the below, which works but it looks very complicated to me and I wonder whether I could have done it in a much simpler way....

VAR SelectedDate = SELECTEDVALUE( Date_Table[Date] )
 
VAR PalletReqTable =
    SUMMARIZECOLUMNS(
        Date_Table[Date],
        Trade_Products[Pack Type],
        FILTER( Trade_Products, Trade_Products[[ID & Text] = "4" ),
        FILTER(
            Date_Table,
          Date_Table[Date] = SelectedDate
        ),
        "Pallet Req", -[# Requirements]
    )
VAR FutsReqTable =
    SUMMARIZECOLUMNS(
        Date_Table[Date],
        Trade_Products[Pack Type],
        FILTER(
            ALL( Trade_Products ),            
                 Trade_Products[Pack Type] = "A"
        ),
        FILTER(
            Date_Table,
          Date_Table[Date] = SelectedDate
        ),
        "Pallet Req", -[# Requirements per Pallet]
    )
VAR UnionTable = UNION( FutsReqTable, PalletReqTable )

VAR FinalSummary =
    GROUPBY(
        UnionTable,
        Date_Table[Date],
                "Total Pallet Req", SUMX( CURRENTGROUP( ), [Pallet Req] )
    )
RETURN
    {
         ROW("Max Total Pallet Req", MAXX(FinalSummary, [Total Pallet Req]))
    }

 

@ValeriaBreve So that would be:

Measure = 
    VAR __Type = MAX( 'PackDimension'[Pack Type] )
    VAR __Date = MAX( 'DateDimension'[Date] )
    VAR __ATable = FILTER( ALL( 'Table' ), [Date] = __Date && [Pack Type] = "A" )
    VAR __Result = IF( __Type = "A", BLANK(), MAX( 'Table'[# Requirements per Pallet] ) - SUMX( __ATable, [# Requirements per Pallet] ) )
RETURN
    __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Hi Greg, got it. I still have my 2 dimension tables - meaning that  I cannot use the [Pack Type] as is in the _ATable because it does not exit in the fact table - fact and dimension are related through Material ID. So I modified it this way:
VAR __ATable =
FILTER(
ALL( PACKED_INV ),
PACKED_INV[START_DATE] = __Date
&& RELATED( Trade_Products[Pack Type] ) = "A"
)
and it works beautifully :-). 

Thank you so much!

 

 

bhanu_gautam
Super User
Super User

@ValeriaBreve , Try using

 

DAX
VAR SelectedDate = SELECTEDVALUE(Date_Table[Date])

// Calculate the total requirements for Pack Type "B" on the selected date
VAR PalletReq =
CALCULATE(
SUM(Trade_Products[# Requirements per Pallet]),
Trade_Products[Pack Type] = "B",
Date_Table[Date] = SelectedDate
)

// Calculate the total requirements for Pack Type "A" on the selected date
VAR FutsReq =
CALCULATE(
SUM(Trade_Products[# Requirements per Pallet]),
Trade_Products[Pack Type] = "A",
Date_Table[Date] = SelectedDate
)

RETURN
PalletReq - FutsReq




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Hi @bhanu_gautam thank you, however this measure is not aggregating by [ID & Text] so when I use it in the table it is returning the [# Requirements per Pallet] per row/[ID & Text]. I did find a solution (as per reply to Greg Deckler) but it si quite complicated - I wonder whether I could simplify it. Anyway, thank you for taking the time to look at this!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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