Power BI Calculate MAX based on the Slicer Selections - powerbi

I have a table which displays hourly pay per position. I'm using MAX(HourlyPay) to get the maximum value in the table and get a value 60 for example. But when I apply a slicer (based on department), the value still show's as 60. Is there a way to recalculate the MAX of HourlyRate based on the Slicers?
Tables:
Occupants
PayDetails (table which contains "Hourly Pay")
OrgStructure (table containing Department slicer)
Relationships:
Occupants to PayDetails (1:1)
Occupants to OrgStructure (*:1)
The column MAX(HourlyPay) which I'm trying to calculate is in the table Occupants.

This should work. Providing the relationship that you have added links to an identical value in each table, then the slicer should filter the hourly pay column as expected.

Related

Get the unique customers with the highest Item value in Table Visualization in Power BI

I am struglling to getting top 25 unique customers when filtering the table using Alert_Id. Basically, I have these columns in table which you can find below. The goal is to show top 25 unique customers based on highest value. The Item can be repeated but name has to be unique. I have tried so many different things but nothing seems to be working as expected because of Multiple customers have used multiple items and hence I am getting duplicate rows. The table has to be dymic because whenever user filters the table using Alert_id it should return those top unique customers that associated with Alert_id(Alert_id is a single selection). So whenever user select their Alert_id that table should display their data. I have tried below measure,
First I created calculated column to break the tie for price because many Item shares the same price:
max price = Table[PRICE] + RAND()
Then I created another column to get max price for the customer name:
MAX column for table = CALCULATE(MAX('Table'[max price]), ALLEXCEPT(Table, Table[CUSTOMER_NAME]))
Then I created calculated table using these columns:
SELECTCOLUMNS(
FILTER(Table, Table[max price]=Table[MAX column for table]), "Name" ,Table[CUSTOMER_NAME],"Item",Table[ITEM], "PRICE",Table[MAX column for table], "Alert_ID", Table[ID], "DATE", Table[REQ_DATE], "ITEM_COUNT", Table[PK])
But, this is giving me all unique customers with the MAX value and I am getting blank table when I filter with Alert_ID even thought it has data but the customers are not with the MAX value. Basically, It's not dynamically capturing max values for each customer_name when filter is applied. And, I if there are multiple rows with same customer name which can have same exact value then I would choose any random row without considering which ITEM it is. I just want top 25 unique customers for one Alert_ID.
Here is the sample data,
Here is expected output if I select Alert_ID = 123 from filter and it can be different when I select different Alert_ID.
FYI: I have tried topn with max price and even with RANKX but no luck. I always endedup having multiple customers.
Any help or lead will be highly appreciated!
I was able to figure out how to get unique values. Here is the solution that worked for me.
First, I created calculated column with my price column and RAND function to break the ties:
sum value = Table[PRICE] + RAND()
Then, I have created one measure that calculates the rank:
rank with table = RANKX(CALCULATETABLE(VALUES('Table'[ITEM]), ALLSELECTED('Table'[ITEM])),CALCULATE(SUM(Table[sum value])), ,DESC, Dense )
Then I applied the filter on NAME column to get top 25 based on sum value calculated column. Also, dragged my measure on filters pane and applied the filter where Rank with table = 1.
That's how I got unique names with highest valued ITEM.

Calculate Works until i add FILTER

I'm learning DAX and I'm trying to make a measure for Sales Last year.
this formula works :
Sales LY = CALCULATE([Sales CY],SAMEPERIODLASTYEAR(Date[Date]))
But when I add FILTER to the measure, it gives me the values from the current year like "Sales CY"
Sales LY = `CALCULATE([Sales CY], Filter (dim_date, SAMEPERIODLASTYEAR (Date[Date]) ))`
I already have a date filter on the page relative date in this year
the invoices Table and Date table are joined on the date of the creation of the invoice (createdat)
Any ideas what's the meaning behind the things in blue circles?
The FILTER function expects a condition that can be checked for each row of the table instead of a column of dates returned by SAMEPERIODLASTYEAR, so I wouldn't expect the second version to work.
I think the bits circled in blue are emphasizing that you are connected an imported data table to a DirectQuery table (different storage modes).

DAX retrieve rows with max value within a group based on date filter

i have the following table with some sample data similar to what we have in our model:
there will be a date filter called "As Of Date" that will be selected by the user. I will need to create a new measure that filters the above table using these rules each time:
rows where reserve date <= the As Of Date selected by the user
rows that are in "Approved" status
for each combination of Claim Id, Damage Id, and Location Id, get the row with the latest sequence number
sum the reserve value column
so based on the sample data above, if the user select an As Of Date of 8-1-2020, the measure should sum the Reserve Value from the following rows that meet the criteria:
What I am trying to achieve is a measure that would return 900 as that is the sum of the reserve values for the rows that meet the criteria, as listed in the second table above.
Thanks
scott

DAX Calculate Sum of sales per productid filter by productid ( NOT IN TOP 20 )

I am fairly new to PowerBI DAX and I want to filter out the top 20 product ids in a measure.
I came up with this formula but it does not seem to be working and I was hoping to get some help here.
$ Amount Parcel =
CALCULATE(
SUM(Data[$ Amount Parcel]),
FILTER (Data, NOT (Data[idProduct], SUM(Data[NetSales])) IN TOPN(20, SUMMARIZE(Data, Data[idProduct], "NetSales", SUM(Data[NetSales]))))
)
I want to show sales per PID for all products except for our 20 best sellers.
Thank you !!
I would suggest an easier approach adding a dimension column.
First of all, you need to have Product dimension table separated from Sales fact table. Make sure to create one-to-many relationship between Product and Sales with "Single" cross filter direction.
Then you can create a calculated column on Product table, which can be used to filter out top selling products.
Sales Rank = RANKX('Product', CALCULATE(SUM(Sales[SalesAmount])))
Now drag and drop Sales Rank field into the Filters pane of your visualization, and set the filter condition so that top selling products will not be shown.

How to pick up column by given parameters and then sum-up the column total in Power BI

I've got a table like below. I would like to pickup the column first by given parameters then sum up the total of the column.
For example, by given Parameter of SGD, I would like to sum-up the total amount of column SGD.
Date SO NO. AUD SGD HKD
7/1/2019 SO1 100 105.17 545.74
8/5/2019 SO2 130 122.01 691.13
9/9/2019 SO3 160 150.32 853.55
9/15/2019 SO4 180 169.11 960.25
Thanks
One way to achieve this is to add a new disconnected table Currencies with one column Currency and values AUD, SGD and HKD. Add a slicer for it and make it drop down.
Then create a measure, which will take the value of the slicer and calculate total on the corresponding column, depending on the selection in the slider:
Total = SWITCH(SELECTEDVALUE('Currencies'[Currency]; "AUD");
"AUD"; SUMX('Table'; [AUD]);
"SGD"; SUMX('Table'; [SGD]);
"HKD"; SUMX('Table'; [HKD]);
SUMX('Table'; [AUD]))
SELECTEDVALUE('Currencies'[Currency]; "AUD") will return the value selected in the slicer, or AUD if none or multiple values are selected. See SELECTEDVALUE.
SWITCH will compare this value with a list of possible options (AUD, SGD and HKD) and return corresponding expression (SUMX('Table'; [AUD]), SUMX('Table'; [SGD]) or SUMX('Table'; [HKD])), or some default value if there is no match (SUMX('Table'; [AUD])).
Then use this measure in your report, and it's value will change depending on the selection in the slicer: