I am trying to count the number of results that are <= 25%.
See bellow for example data
I am trying to create a measure that counts if "Pallet Utilization" is <= 25%.
"Pallet Utilization" is not a column within the data, it would need to be calculated within the measure.
From my understanding, i need to ask the measure to calculate Row by Row?
Bellow is my attempt at doing this however it is returning a count of all rows
AC_Less25 =
CALCULATE (
COUNTAX (
Chilterns_STORAGE,
DIVIDE (
DIVIDE ( Chilterns_STORAGE[NO_CASES], Chilterns_STORAGE[NO_PALLETS] ),
Chilterns_STORAGE[POU_MAX]
) <= 0.25
)
)
Not very experienced with DAX so any help appreciated.
Thanks
So you could use COUNTX, but you can also just use COUNT and add a calculated column.
Add a new Calculated Column:
Pallet Utilization =
DIVIDE (
DIVIDE ( Chilterns_STORAGE[NO_CASES], Cilterns_STORAGE[NO_PALLETS] ),
Chilterns_STORAGE[POU_MAX],
BLANK ()
)
And then add the new measure:
AC_Less25 =
CALCULATE (
COUNT ( Chilterns_STORAGE[Pallet Utilization] ),
FILTER ( Chilterns_STORAGE, Chilterns_STORAGE[Pallet Utilization] <= .25 )
)
EDIT:
If you're dead-set on using COUNTX, something like this would help. In a COUNTX ( or any 'X' measure for that matter ), you define the table you want to iterate over, then provide what it is counting/summing/averaging as the second parameter. So conditions are placed on the table like so:
AC_Less25 = COUNTX(
FILTER(Chilterns_STORAGE,
DIVIDE(
DIVIDE ( Chilterns_STORAGE[NO_CASES], Chilterns_STORAGE[NO_PALLETS] ),
Chilterns_STORAGE[POU_MAX]) <= .25),
Chilterns_STORAGE[NO_PALLETS])
Please note that I'm not sure my Pallet Utilization is correct because I'm not getting the same numbers as you are in your OP... But the screenshot speaks for itself and the CountX above will still do what you want it to do, provided you tweak the conditions in the first parameter of the CountX: DIVIDE(DIVIDE ( Chilterns_STORAGE[NO_CASES], Chilterns_STORAGE[NO_PALLETS] ), Chilterns_STORAGE[POU_MAX]) <= .25))
Related
I'm new to DAX and don't get how it works (I'm studying its context transitions and so on). What I would like to do is to calculate the marked column without duplicating the stock. I mean, it should only sum stock once by PRODUCT. In this case, instead of 480, it should be 240 in every line (including the one that is 0, not sharing product).
This is my measure:
REF STOCK*LINEA :=
CALCULATE (
SUM ( Production[REF_STOCK] );
FILTER (
ALLEXCEPT (Production; Production[SIAC] );
Production[PENDING_UNITS] > 0
&& Production[SIAC 1] <> "SIAC"
)
)
EDIT: I think I made it.
This measure apparently works, but I'm not sure if it is correct for what I want to achieve. Will it work with every case?
REF STOCK*LINEA :=
CALCULATE (
SUMX (
SUMMARIZE ( Production; Production[SIAC]; Production[REF]; Production[Description] );
[Avg of REF_STOCK]
);
FILTER (
ALLEXCEPT ( Production; Production[SIAC] );
Production[PENDING_UNITS] > 0
&& Production[SIAC 1] <> "SIAC"
)
)
Please confirm it should work as expected. Thank you!
Hi guys, I am new to Power BI(DAX formulas) and I am attempting to calculate the percentage contribution of the sum of "count" where "category" = X and "item_no"=1 to the total of "count" across all categories where 'item_no' = 1.
The ideal mathematical statement here will be the (30/50)*100%
I intend to represent the percentage values in a chart showing percentage contribution of each distinct item_no to its total in the format as represented in the example above.
The standard way to approach this is
calculation over partial set / same calculation over larger set
Since you haven't made it clear what context you are trying to calculate this, I will assume it's a visual along these lines:
The measure I use here is
%ItemTotal =
DIVIDE (
SUM ( Table1[count] ),
CALCULATE ( SUM ( Table1[count] ), ALLEXCEPT( Table1, Table1[item_no] ) )
)
In the numerator, you have the sum in the local filter context. For example, in that top-left cell, this means all rows that match item_no = 1 and category = "X".
In the denominator, we do the same thing except we remove all filter context except the context we say to keep (item_no) so it includes all category values.
If you're trying to calculate that 60% outside of the context of a visual, then you can explicitly define what filters you want. For example, this should work in any filter context:
X%_Item1 =
DIVIDE (
CALCULATE (
SUM ( Table1[count] ),
ALL ( Table1 ),
Table1[category] = "X",
Table1[item_no] = 1
),
CALCULATE (
SUM ( Table1[count] ),
ALL ( Table1 ),
Table1[item_no] = 1
)
)
See here and here for other ways to modify the filter context instead of ALLEXCEPT.
I want to create a measure (Average Late) in powerBI that calculates the Maximum of Late per Ordernumber, sum them up & divide the by the number of orders.
enter image description here
I also want this measure to be dynamic and only calculate whats displayed with filters.
enter image description here
I have tried with functions such as CALCULATE, MAX, DISTINCT & SUM.
Try this:
Measure =
VAR distinct_ordernumber =
DISTINCTCOUNT ( 'Table'[OrderNumber] )
VAR sum_max_late_per_ordernumber =
SUMX (
SUMMARIZE ( 'Table'; 'Table'[OrderNumber]; "max_late"; MAX ( 'Table'[Late] ) );
[max_late]
)
RETURN
FORMAT ( sum_max_late_per_ordernumber / distinct_ordernumber; "##.00" )
I want to use a measure and filter the result based on the columns:
My measure is :
TotalProductionCon =
SUM ( _BI_SOVAC_PROD_KIT_LIFE_CYCLE[SGWCP8] )
+ SUM ( _BI_SOVAC_PROD_KIT_LIFE_CYCLE[retard] )
and I want it to summarize only when column année = column year.
I tried CALCULATE and FILTER;
TotalProductionCon =
CALCULATE (
SUM ( _BI_SOVAC_PROD_KIT_LIFE_CYCLE[SGWCP8] )
+ SUM ( _BI_SOVAC_PROD_KIT_LIFE_CYCLE[retard] );
FILTER (
ALL ( _BI_SOVAC_PROD_KIT_LIFE_CYCLE[Année] );
_BI_SOVAC_PROD_KIT_LIFE_CYCLE[Année] = _BI_SOVAC_PROD_KIT_LIFE_CYCLE[year]
)
)
but it generates an error that the columns contain much value and I need to use aggregation.
Can you help me?
The problem with your formula is that you limited ALL function to only one column (Annee), and as a result FILTER does not "see" the other column it needs.
To fix that, change your formula as follows:
TotalProductionCon =
CALCULATE (
SUM ( _BI_SOVAC_PROD_KIT_LIFE_CYCLE[SGWCP8] )
+ SUM ( _BI_SOVAC_PROD_KIT_LIFE_CYCLE[retard] );
FILTER (
ALL (
_BI_SOVAC_PROD_KIT_LIFE_CYCLE[Année];
_BI_SOVAC_PROD_KIT_LIFE_CYCLE[year]
);
_BI_SOVAC_PROD_KIT_LIFE_CYCLE[Année] = _BI_SOVAC_PROD_KIT_LIFE_CYCLE[year]
)
)
I am assuming here that your choice of ALL function is appropriate; otherwise you might need to use a different technique such as SUMMARIZE function.
I'm trying to create a trending table with a value and a forecast. The forecast needs to start from the current month going forward. I am using this dax function:
Spend Forecast =
IF (
OR (
DIVIDE (
CALCULATE (
SUM ( refv_Spend_Cap[Spend_2019] ),
FILTER ( refv_Spend_Cap, refv_Spend_Cap[Split] = "Spend Actual" )
),
1000000
)
< 1,
DIVIDE (
CALCULATE (
SUM ( refv_Spend_Cap[Spend_2019] ),
FILTER ( refv_Spend_Cap, refv_Spend_Cap[Ind_Monthend] = "x" )
),
1000000
)
< 1
),
DIVIDE (
CALCULATE (
SUM ( refv_Spend_Cap[Spend_2019] ),
FILTER ( refv_Spend_Cap, refv_Spend_Cap[Split] = "Spend Forecast" )
),
1000000
),
""
)
The formula is calculating to check if these two conditions are met:
if there's no value then populate the forecast or if the ind monthend = 'x' then it should populate, if those two conditions are not met then it should leave it blank.
There are no syntax errors on the query but i am getting this error:
The True/False expression does not specify a column. Each True/False
expressions used as a table filter expression must refer to exactly
one column
Where did I go wrong?
It's very hard to comprehend such long formulas. It's the best practice to break them down into multiple measures. For example, your code can be re-writen as follows:
Create base measure:
Total Spend = SUM ( refv_Spend_Cap[Spend_2019] ) / 1000000
Now re-use the base measure to create 3 conditional measures. No need to use FILTER here:
Spend Actual = CALCULATE ( [Total Spend], refv_Spend_Cap[Split] = "Spend Actual" )
Spend X = CALCULATE ( [Total Spend], refv_Spend_Cap[Ind_Monthend] = "x" )
Spend Forecast = CALCULATE ( [Total Spend], refv_Spend_Cap[Split] = "Spend Forecast" )
Then the final result is simply:
Forecast = IF ( [Spend Actual] < 1 || [Spend X] < 1, [Spend Forecast], "")
It's much easire to understand what's happening, and easier to debug. You will also gain perfomance bonus because (usually) re-used measures are cached and calculated only once.
Try this code, if it still gives you problems, describe the new error and I'll help you fix it.
BTW, there is a popular free tool to format your DAX code:
Dax Formatter