cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
carlovsky
Helper I
Helper I

Passing a column inside a VAR on Dax

Hi all,

I have this measure: # Products OOS = CALCULATE(DISTINCTCOUNT('Product'[Config_ID]), 'Product'[Stock Max date] = 0)

That has inside:

  • 'Product'[Config_ID] -> Non-calculated column
  • 'Product'[Stock Max date] -> Calculated column

I want to pass 'Product'[Stock Max date] to a variable inside the measure # Products OOS. Can you help me?

Stock Max date = CALCULATE(SUM('Stock'[stock_quantity]),  FILTER('Dim Date', 'Dim Date'[Date] = MAX('Dim Date'[Date])))

 

What am I trying?

carlovsky_0-1642765665911.png

 

carlovsky_1-1642765665917.png

 

 

Thanks

Diego

12 REPLIES 12
v-angzheng-msft
Community Support
Community Support

Hi, @carlovsky 

Try this:

# Products OOS =
VAR Stock_Max_date =
    ADDCOLUMNS(
        stock,
        "xD",
            CALCULATE(
                SUM( 'Stock'[stock_quantity] ),
                FILTER( 'Dim Date', 'Dim Date'[Date] = MAX( 'Dim Date'[Date] ) )
            )
    )
VAR Products_OOS =
    CALCULATE(
        DISTINCTCOUNT( 'Product'[Config_ID] ),
        FILTER( Stock_Max_date, [xD] = 1 )
    )
RETURN
    Products_OOS

If this doesn't work for you, could you please consider sharing more details about it.
It makes it easier to give you a solution.

  1. Sample (dummy dataset) data as text, use the table tool in the editing bar
  2. Expected output from sample data
  3. Explanation in words of how to get from 1. to 2.

 

Best Regards,
Community Support Team _ Zeon Zheng

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

Hi @v-angzheng-msft 

You don't know how incredible you are!!
Still have this issue with the below:


I have three CALCULATED COLUMNS :

average_is = CALCULATE(SUM(Sales[DF Items]), ALLSELECTED(ProdSup[Config_ID])) / 60
stock_max_date = CALCULATE(SUM('Stock'[stock_quantity]), FILTER('Dim Date', 'Dim Date'[Date] = MAX('Dim Date'[Date])))
flg_low_14d = IF(AND('Product'[Average IS]*14 > 'Product'[Stock Max date],'Product'[Stock Max date]>0) , 1, 0)

 

MEASURE:

# Prod coverage<14D = SUM('Product'[FLG_Low_14D])


How can I pass this inside a variable?

What I'm trying:

carlovsky_0-1643127812108.png

 

Hi, @carlovsky 

Try this:

VAR prod_coverage_14d=SUMX(flg_low_14d,[@xD])
RETURN prod_coverage_14d

vangzhengmsft_0-1643160733791.png

 

 

Best Regards,
Community Support Team _ Zeon Zheng


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

Hi @v-angzheng-msft 

Doesn't work :S

 

carlovsky_0-1643186532634.png

 

Hi, @carlovsky 

Try this:

IF ( AND(@average *14 > @stock_max, @stock_max >0),1,0)

vangzhengmsft_0-1643186806664.png

 

 

 

Best Regards,
Community Support Team _ Zeon Zheng

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

Hi @v-angzheng-msft 

Kind odd, but doesn't work. It only recognizes the VAR average_is

carlovsky_1-1643198349973.png

 

 

Hi, @carlovsky 

 

Please consider sharing more details about it and posting expected result so it is clear on what needs to be implemented?  And It would be great if there is a sample file without any sesentive information here.

How to Get Your Question Answered Quickly

 

It makes it easier to give you a solution.

  1. Sample (dummy dataset) data as text, use the table tool in the editing bar
  2. Expected output from sample data
  3. Explanation in words of how to get from 1. to 2.

 

Best Regards,
Community Support Team _ Zeon Zheng

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

Hi @v-angzheng-msft ,

 

Just to remark, my main goal with this is to make some slicers work(Fullfillment type slicer from stock doesnt work because of the calculated columns).

You can find in the link below the sample:

sample 

 

carlovsky_0-1643285196678.png

 

Many thanks sir

Diego

Hi, @carlovsky 

Try this:

VAR _average_is =
    ADDCOLUMNS(
        'Product',
        "@average", CALCULATE( SUM( Sales[DF Items] ), ALLSELECTED( ProdSup[Config_ID] ) ) / 60,
        "@stock_max",
            CALCULATE(
                SUM( 'Stock'[stock_quantity] ),
                FILTER( 'Dim_Date', 'Dim_Date'[Date] = MAX( 'Dim_Date'[Date] ) )
            )
    )
VAR _flg_low_14d =
    ADDCOLUMNS(
        _average_is,
        "@xD",
            IF( AND( [@average] * 14 > [@stock_max], [@stock_max] > 0 ), 1, 0 )
    )
VAR prod_coverage_14d =
    SUMX(_flg_low_14d,[@xD])
RETURN
    prod_coverage_14d

 Result:

vangzhengmsft_0-1643344675062.png

 

 

Best Regards,
Community Support Team _ Zeon Zheng


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

carlovsky
Helper I
Helper I

Any suggestion on how to pass the calculated column to the variable ? Having hard time to filtet using slicers, because i am using calculated columns

VahidDM
Super User
Super User

HI @carlovsky 

 

The ADDCOLUMNS is a tabular function and will return a table so you can not use that VAR in your calculation.

 

Read this: https://radacad.com/power-bi-dax-back-to-basics-scalar-vs-tabular-functions

 

Can yoiu share a sample of your data in a text format with relationships between your tables along with the expected result.

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Daryl-Lynch-Bzy
Solution Sage
Solution Sage

Hi @carlovsky , this part of your sode is not working "stock_max_date = 0".  The reason is the stock_max_date is a Table; not a value.  You would need to change to something like "FILTER ( stock_max_date ,  [xD] = 0 )".  See if this works.

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.