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
Related
I am trying to do a burndown graph on PowerBI.
My data is a list of tasks. Each task has a numerical value (EFFORT) assigned to it and there is a total amount of effort for any given month (sum of all EFFORT). As tasks as set to DONE, the ongoing effort should be deducted from a running total and that value used to plot a graph. I have 3 columns
I would like to have measure to calculate EFFORT REMAINING for each date, i.e.
EFFORT REMAINING = TOTAL EFFORT - (EFFORT WHEN TASKS ARE DONE FOR EACH DAY)
For example,
I did get the consecutive dates displaying:
Burndown = CALENDAR(DATE(2022,7,1),DATE(2022,7,31))
and also the total effort (starting value)
TOTAL EFFORT = SUM(Issues[EFFORT])
Now for each date in table, I need to minus the accumulating total of EFFORT when the status is set to DONE
EFFORT REMAINING = Burndown[TOTAL EFFORT]-SUM(Issues[EFFORT]="DONE" ....
Im stuck after this last point. Can anyone help, please?
you are so close to the answer ). Convert SUM(Issues[EFFORT]="DONE" to:
CALCULATE(
SUM(Issues[EFFORT])
, SUM(Issues[Status]="DONE"
)
Have a nice day.
Please try this measure:
Please ensure that (1-Many) relationship is created between Burndown [Date] and Issues[ISSUE_CREATED] columns.
EFFORT REMAINING =
VAR TblSummary =
ADDCOLUMNS (
SUMMARIZE ( Issues, Burndown[Date] ),
"Total Effort", CALCULATE ( SUM ( Issues[EFFORT] ) ),
"Tasks Completed", CALCULATE ( SUM ( Issues[EFFORT] ), Issues[STATUS] = "DONE" ),
"Effort Remaining",
CALCULATE ( SUM ( Issues[EFFORT] ) )
- CALCULATE ( SUM ( Issues[EFFORT] ), Issues[STATUS] = "DONE" )
)
VAR Result =
SUMX ( TblSummary, [Effort Remaining] )
RETURN
Result
After that, you can create a clustered column chart, and put [Date field] on calendar table on X_axis and put 'EFFORT REMAINING' measure on Y_axis(Value axis) to see the result.
I hope It solves your problem.
Bonus Info:
If you want to see your Summary table, create a "New Table" and paste this code:
Summary_Table =
VAR TblSummary =
ADDCOLUMNS (
SUMMARIZE ( Issues, Burndown[Date] ),
"Total Effort", CALCULATE ( SUM ( Issues[EFFORT] ) ),
"Tasks Completed", CALCULATE ( SUM ( Issues[EFFORT] ), Issues[STATUS] = "DONE" ),
"Effort Remaining",
CALCULATE ( SUM ( Issues[EFFORT] ) )
- CALCULATE ( SUM ( Issues[EFFORT] ), Issues[STATUS] = "DONE" )
)
VAR Result =
SUMX ( TblSummary, [Effort Remaining] )
RETURN
TblSummary
The result It produces:
Note: I have limited access to your data sets as you shared above. The result will be exact with your full dataset.
Please refer to the syntax and table below. I'd like to use the variable, making it more efficient and readable of course, but it doesn't seem to work for me. It is the exact same statement, however I'm (not) defining the variable in the measure "testDAX" ("testDAX2").
I'm looking for the output value being 137, as given by testDAX. The 830 is simply the count of all rows in the table, without applying the filter of ProdCount = 1.
Just added the _tableD6 code. Then I copied the table in the DAX code exactly as is.
FYI: Curbal does the same thing in this video, starting at 3:00, but slightly less complex (without variables). https://www.youtube.com/watch?v=XeV0ndga5kg&t=218s
Thanks in advance!
YK
Code:
testDAX =
CALCULATE (
COUNTROWS (
SUMMARIZE ( Orders, Orders[OrderID], "ProdCount", COUNT ( Orders[ProductID] ) )
),
FILTER (
SUMMARIZE ( Orders, Orders[OrderID], "ProdCount", COUNT ( Orders[ProductID] ) ),
[ProdCount] = 1
)
)
and
testDAX2 =
VAR _tableD6 =
SUMMARIZE ( Orders, Orders[OrderID], "ProdCount", COUNT ( Orders[ProductID] ) )
RETURN
CALCULATE ( COUNTROWS ( _tableD6 ), FILTER ( _tableD6, [ProdCount] = 1 ) )
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 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))
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.