I have a table shown below. I have no issue creating a formula to count the Strike%/Visited. However, if I want to divide it by using the Total Visited by using the measure below, it always returns the same result as in Strike%/Visited.
Strike%/Total Visited = DIVIDE (
SUM ( Table1[Strike] ),
CALCULATE (
SUM ( Table1[Visited] ),
FILTER (
Table1
Table1[year] = "2018"
)
) )
You need to remove the filter context in order to get a total.
Try wrapping an ALL() or ALLSELECTED() function around your first filter argument:
Strike%/Total Visited = DIVIDE (
SUM ( Table1[Strike] ),
CALCULATE (
SUM ( Table1[Visited] ),
FILTER (
ALL(Table1)
Table1[year] = "2018"
)
) )
Related
I have this table :
And I want to calculate for each day and for each group 1and2 % which is
(Attribute1/Attribute2)*100
But I don't want to include 1and2 % in Group Subtotal neither on total
I created a new table :
Table3 = UNION(DISTINCT('Table'[Attributes]);{{"1and2 %"}})
And i made this mesure to calculate 1and2 %:
Measure =
SUMX (
DISTINCT ( 'Table3'[Attributes] );
SWITCH (
'Table3'[Attributes];
"1and2 %"; DIVIDE (
CALCULATE ( SUM ( 'Table'[Value] ); 'Table'[Attributes] = "Attribute1" );
CALCULATE ( SUM ( 'Table'[Value] ); 'Table'[Attributes] = "Attribute2" );
0
) * 100;
VAR a = 'Table3'[Attributes]
RETURN
CALCULATE ( SUM ( 'Table'[Value] ); 'Table'[Attributes] = a )
)
)
And this is the result I'm getting :
I want to exclude 1and2 % (and every Attribute containing % in the future) from group subtotal and the total.
I'm really new to PowerBI and not really familiar with Excel-like formulas.
Can anyone please help me up with that?
Regards
Someone from PowerBI forum gave me this solution and it's exactly what im looking for:
Create another mesure using the existing :
Measure 2 =
VAR __Table =
ADDCOLUMNS(
SUMMARIZE(
'Table 3',
[Group],
[Attribute],
"__Measure",[Measure]
),
"__IncludeInTotals",SEARCH("%",[Attribute],,-1)
)
RETURN
IF(
HASONEVALUE('Table 3'[Attribute]),
[Measure],
SUMX(FILTER(__Table,[__IncludeInTotals] = -1),[__Measure])
)
I think you can get what you want if you only calculate the 1and2 % part when that's the only thing in the filter context and do a normal sum otherwise.
Measure =
IF (
SELECTEDVALUE ( 'Table3'[Attributes] ) = "1and2 %";
DIVIDE (
CALCULATE ( SUM ( 'Table'[Value] ); 'Table'[Attributes] = "Attribute1" );
CALCULATE ( SUM ( 'Table'[Value] ); 'Table'[Attributes] = "Attribute2" );
0
) * 100;
SUM ( 'Table'[Value] )
)
For the subtotals and grand total, SELECTEDVALUE returns blank so the condition fails and you just get the sum.
I'm trying to match the rankorg column with a calculated measure ceiling and pull out the corresponding blackout value -
ValMaxSequence =
CALCULATE (
VALUES ( org[Blackout] ),
FILTER ( ALL ( org[rankorg] ), org[rankorg] = ( [ceiling] ) )
)
I also tried a lookup function, but it needs column value, but I have the result in a measure
The ceiling measure is being calculated within the context of the FILTER function.
Try pre-calculating it before you use it inside another function.
ValMaxSequence =
VAR Ceil = [ceiling]
RETURN
CALCULATE (
VALUES ( org[Blackout] ),
FILTER ( ALL ( org[rankorg] ), org[rankorg] = Ceil )
)
I've been trying to get the sum of the following table's column VALUE using DaxStudio in order to put that on PowerBI once is's ok, since PBI can get slow if you test a code for large calculated tables.
Table from DaxStudio
BU VALUE
------------------------
FOODS 0.0000
FIBI 0.0000
GEOS/CIS 0.7300
CASC
S_S
SGS
COCOA
COCOA/SSSA
CORPORATE
N/A
CIS
The code behind it:
DEFINE
VAR TOTAL =
CALCULATE (
SUMX (
PACKAGING_POWERBI_YEARLY_2;
PACKAGING_POWERBI_YEARLY_2[QUANTIDADE_ANTERIOR]
);
FILTER (
PACKAGING_POWERBI_YEARLY_2;
PACKAGING_POWERBI_YEARLY_2[DATE] = "2018"
&& PACKAGING_POWERBI_YEARLY_2[CODIGO] = "43130"
)
)
EVALUATE
SUMMARIZE (
CALCULATETABLE (
FILTER (
PACKAGING_POWERBI_YEARLY_2;
PACKAGING_POWERBI_YEARLY_2[PRECO_PONDERADO] <> BLANK ()
&& PACKAGING_POWERBI_YEARLY_2[PRECO_PONDERADO] <> 0
)
);
PACKAGING_POWERBI_YEARLY_2[BU];
"VALUE"; FORMAT (
(
CALCULATE (
SUMX (
PACKAGING_POWERBI_YEARLY_2;
PACKAGING_POWERBI_YEARLY_2[QUANTIDADE_ANTERIOR]
);
FILTER (
PACKAGING_POWERBI_YEARLY_2;
PACKAGING_POWERBI_YEARLY_2[DATE] = "2018"
&& PACKAGING_POWERBI_YEARLY_2[CODIGO] = "43130"
&& PACKAGING_POWERBI_YEARLY_2[PRECO_PONDERADO] <> BLANK ()
)
) / TOTAL
)
* (
CALCULATE (
SUMX ( PACKAGING_POWERBI_YEARLY_2; PACKAGING_POWERBI_YEARLY_2[PRECO_PONDERADO] );
FILTER (
PACKAGING_POWERBI_YEARLY_2;
PACKAGING_POWERBI_YEARLY_2[DATE] = "2018"
&& PACKAGING_POWERBI_YEARLY_2[CODIGO] = "43130"
&& PACKAGING_POWERBI_YEARLY_2[PRECO_PONDERADO] <> BLANK ()
)
)
);
"0.0000"
)
)
Instead of generating the table I would like to sum the results of column VALUE, but the only way I got to plot a result without error is through a "CALCULATED TABLE" (above).
Every filter I try leads to an error.
The idea is to get just the sum of that calculated column VALUE:
0.7300
But every simpler filter or SUMX condition I try, an error pops-up.
I'd think you could clean it up to look something like this:
CALCULATE (
SUMX (
VALUES ( PACKAGING_POWERBI_YEARLY_2[BU] ),
SUM ( PACKAGING_POWERBI_YEARLY_2[QUANTIDADE_ANTERIOR] )
/ CALCULATE (
SUM ( PACKAGING_POWERBI_YEARLY_2[QUANTIDADE_ANTERIOR] ),
ALL ( PACKAGING_POWERBI_YEARLY_2[BU] )
)
* SUM ( PACKAGING_POWERBI_YEARLY_2[PRECO_PONDERADO] )
),
FILTER (
PACKAGING_POWERBI_YEARLY_2,
PACKAGING_POWERBI_YEARLY_2[DATE] = "2018"
&& PACKAGING_POWERBI_YEARLY_2[CODIGO] = "43130"
&& PACKAGING_POWERBI_YEARLY_2[PRECO_PONDERADO] <> BLANK ()
&& PACKAGING_POWERBI_YEARLY_2[PRECO_PONDERADO] <> 0
)
)
This uses SUMX to iterate through each of the BU values and for each one, calculates the value
(QUANTIDADE_ANTERIOR / Total QUANTIDADE_ANTERIOR ) * PRECO_PONDERADO
where the filters are reused instead of repeated.
I can't guarantee that this code works exactly as intended, but it should point you in a better direction.
Situation:
I have a column in my table with values representing weeks of the year.
Each week number has their respective total counts of purchases on another column. When I use a matrix visual and put that specific column in the Columns section it separates them distinctively which is what I want. How can get the % change from one week to another?
Table looks like this:
Objective:
Create a measure that can divides column 2 by column 1 to get the % change.
Layout of Matrix:
Ideally I would like to have a third column to calculate the values in column 6 by the ones in column 5.
OK, here is one solution:
Delta :=
VAR Week5 =
CALCULATE ( SUM ( 'Table'[Total] ), FILTER ( 'Table', 'Table'[Weeks] = 5 ) )
VAR Week6 =
CALCULATE ( SUM ( 'Table'[Total] ), FILTER ( 'Table', 'Table'[Weeks] = 6 ) )
RETURN
IF (
SUM ( 'Table'[Total] ) = SUMX ( ALL ( 'Table' ), 'Table'[Total] )
|| SUM ( 'Table'[Total] )
= SUMX (
FILTER ( ALL ( 'Table' ), 'Table'[Cohort] = MAX ( 'Table'[Cohort] ) ),
'Table'[Total]
),
100*DIVIDE ( Week6 - Week5, Week5 ),
BLANK ()
)
I tested it and it works:
BUT because the way your data is structured, it makes it very difficult (for me) to make this pretty. But hey, it works!! ;) I wasn't sure which direction you needed the delta but that is a simple change in the measure from this:
100*DIVIDE ( Week6 - Week5, Week5 )
To this:
100*DIVIDE ( Week5 - Week6, Week6 )
Hope this help!
Problem:
I need a calculated measure in DAX that sums the Value column for the last 6 sprints. I am basing the last 6 sprints on the DimSprintEndDateKey in descending order.
Table structure in PowerBI
The DAX that I am using:
CALCULATE (
SUM ( factSprint[Value] ),
FILTER (
ALL ( factSprint ),
COUNTROWS (
topn(6,
FILTER (
factSprint,
EARLIEST( RELATED ( dimSprint[DimSprintEndDateKey] ) )
> RELATED ( dimSprint[DimSprintEndDateKey] )
),RELATED ( dimSprint[DimSprintEndDateKey] ), DESC
)
)
)
)
I am assuming that the relationship on your tables is between 'dimSprint'[dimSprintKey] and 'FactSprint'[dimSprintKey].
That being the case, this measure could work for you.
Total Value Last Six Sprints =
VAR endDateSprint =
LOOKUPVALUE (
'dimSprint'[dimSprintEndDateKey],
'dimSprint'[dimSprintKey], SELECTEDVALUE ( 'FactSprint'[dimSprintKey] )
)
VAR dimTableFiltered =
FILTER ( 'dimSprint', 'dimSprint'[dimSprintEndDateKey] <= endDateSprint )
RETURN
CALCULATE (
SUM ( 'FactSprint'[Value] ),
ALL ( 'FactSprint' ),
TOPN ( 6, dimTableFiltered, [dimSprintEndDateKey], DESC )
)
Use it on a matrix visual (or pivottable). Be sure to put 'FactSprint'[dimSprintKey] or 'FactSprint'[SprintPK] on Rows and [Total Value Last Six Sprints] on Values.