I have to make a slicer with two option "Top 5" and "All Others" which should give me results as mentioned below - matrix

I have to make a slicer to pick rows from this data (i.e. if I choose top 5 option in slicer than all the top 5 rows for each value of column A should appear and if I choose all other option from slicer then all the values except top should appear). Let me explain you by table
Here is the data table
Our slicer will have two options one "Top 5" and another "All Others".
If I choose top 5 then i should get a table like below mentioned:
And If I choose "All Other Option in Slicer then I should get the Following Table:

You can create a measure with below code and use it as filter on your visual.
Filter_Measure =
IF (
(
SELECTEDVALUE ( Slicer_Value[selection] ) = "Top 5"
&& MAX ( 'Table'[Rank] ) <= 5
)
|| (
SELECTEDVALUE ( Slicer_Value[selection] ) = "All Others"
&& MAX ( 'Table'[Rank] ) > 5
),
1,
0
)
PFA screenshot of visual with filter

Related

Calculate the difference between the current and the previous row in DAX

In Analysis Services I have a table for Covid Cases, as shown below:
It shows the cumulative cases on a daily basis for 193 different countries. I would like to add a calculated column to calculate the difference between the current row and the previous row, so I can see the daily new cases. Also, as column Country/Region contains 193 different countries, this calculation needs to be somehow grouped for each country. The Date column should also be in the right order.
How should I sort the table and what DAX function should I use to make this work?
Try this
Column =
VAR current =
CALCULATE ( MAX ( tbl[Value] ) )
VAR prev =
MAXX (
FILTER (
tbl,
tbl[Country] = EARLIER ( tbl[Country] )
&& tbl[Date] < EARLIER ( tbl[Date] )
),
tbl[Value]
)
RETURN
current - prev

Ranking results from a SUMMARIZECOLUMNS operation

I created the following DAX code in DAX Studio which works correctly:
EVALUATE
SUMMARIZECOLUMNS(
'Florida Sightings'[Locality Id],
Hotspot[Subnational 1 Code],
Hotspot[Name],
'Calendar'[Month],
FILTER(Hotspot, Hotspot[Subnational 1 Code] = "US-FL"),
"Species Count", COUNTROWS(VALUES('Florida Sightings'[Common Name]))
)
The output looks like this, sorted by month and species count:
I would like to take the results of the SUMMARIZECOLUMNS and add a rank column based on species count for each locality Id and month. So, for the first locality Id (L127258) and Month (1), the rank would be 1. And, for the second locality Id (L123565) and month (1), the rank would be 2 etc.
The months run from 1 through 12 for each locality.
Without sample data to work with, I'm shooting in the dark a bit but try something along these lines:
ADDCOLUMNS (
SummaryTable,
"Rank", RANKX (
FILTER (
SummaryTable,
[Locality Id] = EARLIER ( 'Florida Sightings'[Locality Id] )
&& [Month] = EARLIER ( 'Calendar'[Month] )
),
[Species Count]
)
)

How to combine 6 tables in one Matrix, show top 12 and categorize the rest as others?

I need to be able to sum availability based on product and say show me top 3, and categorize the rest as Others. I have two tables in a matrix connected by a product table.
I tried so many ways -
i was able to create this measure for July (which is what i will be sorting with) - I get the correct ranking column for July.
i know i'm missing something. i tried to take that ranking measure statement and add an if statement and couldn't get it to do the ranking.
the picture would make more sense *(my formulas are based on actual column names)
Partner Ranking =
VAR summry =
SUMMARIZE (
ALLSELECTED ( Latest ),
[partner_group],
"Sum", COUNT ( Latest[site_url] )
)
VAR tmp =
ADDCOLUMNS ( summry, "RNK", RANKX ( summry, [Sum],, DESC, DENSE ) )
RETURN
MAXX (
FILTER ( tmp, [partner_group] = SELECTEDVALUE ( Latest[partner_group] ) ),
[RNK]
)
I don't know what to do next. how can i do this when i have a separate table that is the product name that links the two tables?

TOP 10 Values in DAX Aggregation

I want to show top 10 customers with highest sales amount in DAX.
please let me know why this formula doesn't work, and what is the best syntax?!
DEFINE
MEASURE InvoiceLines[Sales] = sumx(InvoiceLines,InvoiceLines[Quantity]*InvoiceLines[UnitPrice])
EVALUATE
TOPN(10,
SUMMARIZE(
Customers,
Customers[customerID],Customers[CustomerName],
"Sales" ,InvoiceLines[Sales]
)
, InvoiceLines[Sales],DESC
)
There are several ways of achieving this; the easiest is to create a simple measure to calculate sales amount in DAX:
Total Sales := CALCULATE(SUM('Table'[Sales]))
Then you can simply use this in the "Top N" filtering option on the "Visual Level Filters" pane in the .pbix, you simply drop in the measure and choose 10 as your N parameter.
A more complicated way that I've done it in the past, using DAX:
Top 10 Customers :=
VAR RankingContext =
VALUES ( 'Customers'[CustomerName] )
VAR TopNumber = 10
RETURN
CALCULATE (
[Total Sales],
TOPN ( TopNumber, ALL ( 'Customers'[CustomerName] ), [Total Sales] ),
RankingContext
)
I hope this helps!! (I'd go with option #1)

Powerpivot: Retrieve max value for a group in a related table

I have 2 tables with a one-to-many relationship.
-TableGroup: table with groupletter
-TableAll: table with unique identifier, groupletter, a date
Problem: I want to get the max value of the date from TableAll into a new column in TableGroup. See below.
Question: What is the formula for column MAXdate?
TableAll:
ID | Group | date
1 A 4/01/2017
2 A 2/10/2016
3 A 2/06/2016
4 B 2/12/2016
5 B 15/12/2016
6 B 2/03/2017
7 C 5/02/2016
8 C 16/01/2016
TableGroup:
Group | MAXdate
A 4/01/2017
B 2/03/2017
C 5/02/2016
The below formula doesn't work:
See here
The answer is:
CALCULATE (
MAX ( TableAll[Date] ),
FILTER ( TableAll, TableAll[Group] = EARLIER ( TableGroup[Group] ) )
)
Try:
CALCULATE (
MAX ( TableAll[Date] ),
FILTER ( TableGroup, TableGroup[Group] = EARLIER ( TableGroup[Group] ) )
)
How it works:
EARLIER ( TableGroup[Group] ) expression essentially means "current row". Filter function goes row by row over TableGroup table, filters it by current row's group, and then finds max date for that group.

Resources