I am using rank based on the number of incidents per site, but there are sites where it has the same number of incidents, but I get ties, and I would like to break the tie.
Rank_4 =
IF(
HASONEVALUE('inci soporte_nuevo'[pb_cod_nom]),
RANKX(
ALLSELECTED('inci soporte_nuevo'[pb_cod_nom]),
CALCULATE(
SUM('inci soporte_nuevo'[nro_inc])
),
,
DESC
)
)
enter image description here
What should I add in the rank_4 measure?
When you look at the help of DAX RANKX, you can see there is an option on how to handle ties:
RANKX(<table>, <expression>[, <value>[, <order>[, <ties>]]])
So in your case you can simply write Dense as option to RANKX:
RANKX(
ALLSELECTED('inci soporte_nuevo'[pb_cod_nom]),
CALCULATE(
SUM('inci soporte_nuevo'[nro_inc])),
,
DESC, Dense
)
Related
Link: https://www.sqlbi.com/articles/specifying-multiple-filter-conditions-in-calculate/
I am reading this article about a new DAX feature added to CALCULATE, that allows referencing multiple columns in the same predicate. Example:
Red or Contoso Sales :=
CALCULATE (
[Sales Amount],
'Product'[Color] = "Red" || 'Product'[Brand] = "Contoso"
)
This question is not about the above concept, but about the quote below. Specifically - Why is the author saying that using table filter is a common error? What is the problem with using table filter instead of a multi-column filter? I want an example to understand this.
Red or Contoso Sales := CALCULATE (
[Sales Amount],
FILTER (
ALL ( 'Product'[Color], 'Product'[Brand] ),
'Product'[Color] = "Red" || 'Product'[Brand] = "Contoso"
) )
A common error is to use a table filter instead of a multi-column
filter. For example, the Big Sales Amount measure or the initial
example is often written in this sub-optimal manner:
Big Sales Amount := CALCULATE (
[Sales Amount],
FILTER (
Sales,
Sales[Quantity] * Sales[Net Price] > 1000
) )
When you create a filter clause, the DAX engine creates a table. So in this case
Big Sales Amount := CALCULATE ( [Sales Amount], FILTER ( Sales, Sales[Quantity] * Sales[Net Price] > 1000 ) )
It is loading the table 'Sales' completely in the background, then applying the formula on two columns in that table. If it is a wide table in terms of the number of columns, this will use up memory with irrelevant columns needed for the calculation. Marco Russo calls this a 'slow' pattern.
So it would be better to create a measure that only uses the two columns needed, so the filter creates a table in the background that is the minimum for use.
So the above could be done as
Big Sales Amount := CALCULATE ( [Sales Amount], FILTER ( ALL ( Sales[Quantity], Sales[Net Price] ) * Sales[Net Price] > 1000 ) )
So the multi-column version is a lot lower in the memory overhead (called a 'fast' pattern) as it is only using the two columns needed, but as you use ALL you may need a KEEPFILTER in the formula to get the correct results. The DAX Engine has been updated and optimized so it will do this sort of table to column reduction without declaring it explicitly.
I am brand new to Power BI, and I could use a bit of help. I have this sample data:
I then want to get the [Average Total Billed Per Profession], which I got using:
Then, ideally, I would [Total Billed]/[Average Total Billed Per Profession]. But when I drop it in a table, it breaks. On the left, are the values I would want in the calculation. On the right, the values I get:
How would I set up the calculation correctly? Any help is appreciated. Thanks.
To have the average per profession in a table where also the Name is present, it's necessary to remove the filter context over Name, so a possible solution is
Average Total Bille Per Profession =
CALCULATE(
AVERAGEX(
SUMMARIZE( StaticData, StaticData[Profession], StaticData[Name] ),
CALCULATE( SUM( StaticData[Price] ) )
),
ALLEXCEPT( StaticData, StaticData[Profession] )
)
The CALCULATE inside AVERAGEX is required to trigger a context transition to transform the row context on the StaticData columns to a the corresponding filter context, that's needed to filer the StaticData[PriceColumn] rows to be used in the SUM.
It looks like profession + name doesn't make each row unique. If you just want "Average Total Billed Per Profession", then you can use something like the following.
Average Total Bille Per Profession =
AVERAGEX(
VALUES( StaticData[Profession] ),
SUM( StaticData[Price] )
)
It's just making sure you're considering unique profession for the metric you're calculating.
So, I have the following tables in my Power BI :
Sales : Date | ID_Client | ID_Product | Amount
Client : ID_Client | Name_Client
I would like to get the number of unique BIG clients in any given month. I therefore use the following formula (which I then put in a column in a table with months in rows):
# BIG Clients =
VAR threshold = 10000
RETURN
(
CALCULATE(
DISTINCTCOUNT( Sales[ID_Client] ),
FILTER(
SUMMARIZE(
Sales,
Sales[ID_Client],
"Sales", SUM( Sales[Amount] )
),
[Sales] >= threshold
)
)
)
QUESTION IS : how can I get the list of those BIG clients for any given month? Let's say I click on the November number of big clients in my table, could another table nearby display the list of those clients ?
Thanks in advance for your kind help, I've been trying for a while :)
I assume that you have a table of clients with the Name column with a one to many relationship with the Sales table and that you do not have duplicate client names. Then you may create a [BIG Sales] measure to be used in a table or matrix visual with client names on the rows.
since [BIG Sales] evaluates to BLANK() for clients with less that threshold sales, they are automatically filtered out from the visual
BIG Sales =
VAR threshold = 10000
VAR BigCustomers =
FILTER(
ADDCOLUMNS(
VALUES( Clients[Name] ),
"Sales", SUM( Sales[Amount] )
),
[Sales] >= threshold
)
RETURN
SUMX(
BigCustomers,
[Sales]
)
You could create a table or matrix visual with the client on the rows and use your measure in the values field. This will show 1 for all big clients and return blank for the rest (which should hide them). If you don't want to show the measure, you can set the value is 1 in the filter pane and remove the measure from the values field.
A more direct option is to use a simple SalesAmount = SUM ( Sales[Amount] ) measure in the values field and filter like this
I face difficulties with applying the RANKX function.
The ranking in the example below should be dynamically modified by Customer in the Matrix Rows, Year in the Matrix Columns and Group, Year and Week in the slicers. The ranking is based on the Volume measure shown herebelow.
Issue:
When all weeks are selected the ranking works fine, but whenever I filter on certain weeks the ranking shows double ranks. How can I solve this?
The DAX I used:
Rank =
RANKX( ALL(Volume[Customer]), Volume[Volume],,DESC, Dense)
Volume = SUM(Volume[Total Volume])
Screenshots of the matrix
1. Matrix when all weeks are selected, showing the right ranks
2. Matrix when certain weeks are selected, showing wrong ranks
Can you try with this below code-
Rank =
RANKX(
ALLSELECTED(Volume[Customer]),
Volume[Volume],
,
DESC,
)
Since we have a single table instead of a star schema there are cross-filtering effects. To remove these we must first remove the whole filtering, then apply back the desired filters from the visual and from the slicers.
Rank 1 =
VAR Customers =
ALLSELECTED( Volume[Customer] )
VAR Result =
CALCULATE(
RANKX( Customers, Volume[Volume],, DESC, DENSE ),
REMOVEFILTERS( Volume ),
VALUES( Volume[Year] ),
VALUES( Volume[Customer] ),
ALLSELECTED( Volume[Week] )
)
RETURN
Result
Since there are no slicers on Customer, we might also use ALL instead of ALLSELECTED
I need to perform a simple calculation in DAX that consists of 2 steps.
Step 1: Calculate the median price change (%) per product.
Step 2: Calculate the average of all the medians calculated in Step 1 while counting each product (calculated median) only once.
Using a calculated column for Step 1 doesnt seem to work out for me because the medians from Step 1 are subject to change as soon as the user filters the table (i.e. using a date slicer) in the report.
Therefore, I will need to get both Steps performed dynamically in a measure.
I'm pretty sure the answer to: "Is there any way to achieve this?" will be "Yes". I just lack the know-how at this point and can't seem to find the answer.
I would recommend to create 2 differents measures to solve this problem.
But since you need to create only 1 measure you can use the following DAX function:
Median_per_product =
VAR __step1 = CALCULATE( MEDIAN('Table'[Price_Change] ), ALLEXCEPT('Table', 'Table'[Product] ))
VAR __step2 = AVERAGEX( VALUES( 'Table'[Product] ), CALCULATE( MEDIAN( 'Table'[Price_Change] ) ) )
RETURN
IF(
HASONEVALUE('Table'[Product]) &&
NOT(ISBLANK( __step1 )),
__step1,
__step2
)
This is the expected result: