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
carlovsky
Helper II
Helper II

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 II
Helper II

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
Resident Rockstar
Resident Rockstar

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
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.

Top Solution Authors