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
Related
I've got the following DAX Measure that provides me with the ability to filter down to the last XX of activity from an individual.
I can only seem to add the measure to the Filter on Visual so when chosing to filter down on say the last 10 this does not update other visuals in the report.
What can I do so that I am able to view the last 10 activities, but for the other visuals to update?
Rank = RANKX
(ALLEXCEPT(Sheet1,Sheet1[Name]),
CALCULATE(MAX(Sheet1[Date])),,
DESC)
It's likely you are applying that filter to only one visual.
It's better to implement the logic in the DAX calculation.
DAX Calculation
Rank =
VAR _Calc =
RANKX (
ALLEXCEPT ( Sheet1, Sheet1[Name] ),
CALCULATE ( MAX ( Sheet1[Date] ) ),
,
DESC
)
RETURN
IF ( _Calc <= 10, _Calc )
I have two data bases.One contain carder and other one contain data.What I want is once I select the designation from the slicer.Then select the the employee and need to show higher defect rate styles.I have set little slicer to select higher 1 ,2 ,3 defect rate styles. .My measures as below.
Total Check = SUM(Records[Check Qty])
Total Defects = SUM(Records[Defects])
Selected_Top_N = SELECTEDVALUE('Top N'[Column1])
Defect pct = CALCULATE((DIVIDE([Total Defects],[Total Check])),TOPN([Selected_Top_N],ALL(Records[Style]),DIVIDE([Total Defects],[Total Check]),DESC),VALUES(Records[Style]))
This "Defect pct" measure works fine for Executive grade. Because it has active relationship. For qc it shows blank. My question is how to modify "Defect pct" measure using "userrelationship" or any other dax function to see top styles once I clicked qc from designation slicer and qc from the employee list.Without unpivoting I can get check qty and defect qty like below with %.by selected value for designation.'code'
Selected_designation = SELECTEDVALUE(Carder[Desingation])
SWITCH(true(),[selected_designation] ="Executive",DIVIDE([Total Defects],[Total Check]),
[selected_designation] ="QC",CALCULATE(DIVIDE([Total Defects],[Total Check]),USERELATIONSHIP(Records[QC],Carder[EMPLOYEE])))
'then using switch function I get these with two calulations.one for the direct relation ship.and other calculation with userrelationship for inactive one.I want rank this % with topN.End result must be once I click excetive I want rank higher defect % pct according to the selected executive and once I click qc I want the same.
You need first to convert your fact table into this shape using unpivoting the last 2 columns.
Like This:
Then Create a designation Table consisting of 2 columns:
Like This:
Your Final Model View should appear like this:
(Updated) DAX Code For Defect pct:
Defect pct =
VAR selection =
SELECTEDVALUE ( Carder[Desingation] )
VAR conditional_selection =
SWITCH (
selection,
"Executive", CALCULATE ( MAXX ( Records, DIVIDE ( [Total Defects], [Total Check] ) ) ),
"QC",
CALCULATE (
MAXX ( Records, DIVIDE ( [Total Defects], [Total Check] ) ),
USERELATIONSHIP ( Records[QC], Carder[EMPLOYEE] )
)
)
RETURN
conditional_selection
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 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
)
I having trouble calculating the cumulative sum of a column on PowerBI.
I have a big offer table and I want to run a pareto analysis on it. Following many tutorials, I created a SUMMARIZED table by offer and a sum of their sales. So the table definition is:
summary = SUMMARIZE(big_table; big_table[offer]; "offer sales"; sum(big_table[sales]))
Many of the forums and stackoverflow answers I found have direct me to the following formula for cumulative sum on column:
cum_sales =
CALCULATE(
sum([offer_sales]);
FILTER(
ALLSELECTED(summary);
summary[offer_sales] <= max( summary[offer_sales])
)
)
However the resulting table is not correct:
What I need is simply to have the offers ordered by sales descending and then add the current row's sales amount to the previous row's sales,
So I excepted numbers closer to:
1st row: 1.5M
2nd row: 2.1M
3rd row: 2.6M and so on
But (maybe) because of my data structure and (certainly) lack of knowledge on how PowerBI works, I'm not getting the right results...
Total Amount = SUM ( 'Fact'[Amount] )
Offer Visual Cumulative =
VAR OfferSum =
ADDCOLUMNS (
ALLSELECTED ( 'Offer'[Offer] ),
"amt", [Total Amount]
)
VAR CurrentOfferAmount = [Total Amount]
VAR OffersLessThanCurrent =
FILTER (
OfferSum,
[amt] <= CurrentOfferAmount
)
RETURN
SUMX (
OffersLessThanCurrent,
[amt]
)
There's no need to pre-aggregate to a summary table. We can handle that as in the measure above.
This assumes a single fact table named 'Fact', and a table of distinct offers, 'Offer'.
Depending on what you're doing in terms of other filters on 'Offer', you may need to instead do as below:
Offer Visual Cumulative =
VAR OfferSum =
ADDCOLUMNS (
ALLSELECTED ( 'Offer'[Offer] ),
"amt", CALCULATE ( [Total Amount], ALLEXCEPT ( 'Offer', 'Offer'[Offer] ) )
)
...
The rest of the measure would be the same.
The measure is fairly self-documenting in its VARs. The first VAR, OfferSum is a table with columns ('Offer'[Offer], [amt]). This will include all offers displayed in the current visual. CurrentOfferAmount is the amount for the offer on the current row/axis label of the visual. OffersLessThanCurrent takes OfferSum and filters it. Finally, we iterate OffersLessThanCurrent and add up the amounts.
Here's a sample: