DAX FORMAT function cause cartesian product on Power BI visual - powerbi

I have the following SSAS Tabular model defined:
On the Product table, I have the following measures defined:
DeliveryQty2018:= CALCULATE ( SUM ( PurchaseDelivery[PurchaseOrderQuantity] ), ( PurchaseEstimatedWarehouseArrivalDate[PurchaseEstimatedWarehouseArrivalYear] = 2018 ) )
DeliveryQty2019:= CALCULATE ( SUM ( PurchaseDelivery[PurchaseOrderQuantity] ), ( PurchaseEstimatedWarehouseArrivalDate[PurchaseEstimatedWarehouseArrivalYear] = 2019 ) )
Sum DeliveryQty 2018-2020: = FORMAT([DeliveryQty2018] + [DeliveryQty2019] + [DeliveryQty2020],"# ### ###")
I'm creating a table visual on my Power BI report, that consists of the following fields:
This combinations gives me a cartesian product of: Product X ProductCategory:
What's interesting, when I remove the FORMAT() wrapper for the Sum DeliveryQty 18-20, cartesian product is removed and I achieve the single record I was loooking for. However, if I remove the ProductCategory field and leave the Sum DeliveryQty 18-20 measure with the FORMAT() function in place I also get the single record..
Can anyone explain to me what's going here in both scenarios?

FORMAT turns blanks (nulls) into empty strings "" rather than proper blanks, so you probably want to check for that first before formatting.
Sum DeliveryQty 2018-2020: =
VAR Qty = [DeliveryQty2018] + [DeliveryQty2019] + [DeliveryQty2020]
RETURN
IF ( ISBLANK ( Qty ), BLANK(), FORMAT ( Qty, "# ### ###" ) )

Related

DAX Measure: case based on other column text values

I have a big model in PowerBI where there are many different aggregation and grouping based on columns being displayed or not on the final table.
Simplifying: I need to do a conditional statement doing the sum if the value of column 1 is A1 but doing the MAX() if the value of column 1 is A2.
I need to have that information in the same column of the final output.
How would you go for this one?
Thank you very much for your help!
if you have only two values you can do a simple IF like this :
Measure = IF ( SELECTEDVALUE('Table'[Column1]) = "A1", SUM('Table'[Column2]), MAX('Table'[Column2]))
Please try this code:
TblMeasure =
VAR TblSummary =
ADDCOLUMNS (
VALUES ( FactTable[Column1] ),
"Test",
IF (
FactTable[Column1] = "A1",
SUM ( FactTable[Column2] ),
MAX ( FactTable[Column2] )
)
)
RETURN
SUMX ( TblSummary, [Test] )
If we test it on a table visual:

Percentage value of a segment against segment total Power BI(DAX)

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.

filtering measures based on two columns in power bi dax

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.

Filter a column dynamically using a measure in Power BI

There is a column with FY i.e. "FY19","FY18","FY17" etc.
I Created a measure which calculates the current FY:
CurrFY =
CONCATENATE (
"FY",
IF (
MONTH ( TODAY () ) <= 3,
VALUE ( FORMAT ( TODAY (), "YY" ) ),
VALUE ( FORMAT ( TODAY (), "YY" ) ) + 1
)
)
e.g. output: "FY19"
Now i need to filter the report based on the FY column using the current FY i get from the CurrFY measure.
How do i do it?
Create a calculated column on your table using that measure
FYFilter = IF(Table1[FY] = [CurrFY], 1, 0)
Then add that column as a report level filter where FYFilter is 1.

Sum of a measure per date range

I have the following Table Visualization.
I'd like the table to look like the following. Column C should be averaging the range of Column B.
For example:
C2 = AVERAGE(B2:B2)
C3 = AVERAGE(B2:B3)
C4 = AVERAGE(B2:B4)
and so on.
The Year-Month column is from my MonthTable. The schema is as follows,
And the Sum measure DAX is as follows,
For the CumulativeSum measure, I have tried the following.
CumulativeSum =
CALCULATE(
[Sum],FILTER(AppendedTables,AppendedTables[Year-Month] <= MAX(AppendedTables[Year-Month]))
)
I'm guessing the issue is my CALCULATE([SUM]) area. I wanted to wrap [SUM] in a SUM() method, but that doesn't work. It gives the error "The SUM function only accepts a column reference as the argument number 1".
Please enlighten me.
I've been able to produce your desired results by creating a calculated column using the following code:
CumSum =
VAR CntRow =
COUNTROWS ( FILTER ( Sheet1, [Year-Month] >= EARLIER ( [Year-Month] ) ) )
VAR CumSum =
CALCULATE (
SUMX ( Sheet1, Sheet1[Sum] ),
FILTER ( Sheet1, Sheet1[Year-Month] >= EARLIER ( Sheet1[Year-Month] ) )
)
RETURN
DIVIDE ( CumSum, CntRow )
Hope this helps!!