I have the below data:
(last column shall be a sum grouped by BU and UP).
I have achieved the last column SubTotalBU, by doing:
SubTotalBU = CALCULATE ( sum(Sheet1[NSR]), ALLSELECTED(), VALUES(Sheet1[BU]), VALUES(Sheet1[UP]) )
My goal is to get the max of column SubTotalBU for each UP… That is; I need a column with all values 90 in this case.
I have tried using MAX of SubTotalBU, but MAX doesn’t work with measures… How can I get the desired result?
To display all max total in your table report, you need to create a new column for the value, else the table will auto filter the value base on the table row:
First, create new column for Total BU:
Tottal BU = CALCULATE(SUM(Sheet1[NSR]),FILTER(Sheet1,Sheet1[Bu] = EARLIER(Sheet1[Bu])))
Next, create a new column to record only max value from the Total BU
Max BU = MAX(Sheet1[Tottal BU])
Sample data with new column:
Table Report:
Related
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.
I use DAX to add two new columns "netWeight_Shipped" and "NetWeight_notShipped" based on existing column "NetWeight_Total" and groupped by "BatchNo" and filtered by OutStockTransactionID as below:
--New column
NetWeight_Shipped =
CALCULATE(
SUM(Fact_ShippingKPI[NetWeight_Total])
,ALLEXCEPT(Fact_ShippingKPI,Fact_ShippingKPI[BatchNo])
,Fact_ShippingKPI[OutStockTransactionID] <> 0
)
--New column
NetWeight_notShipped =
CALCULATE(
SUM(Fact_ShippingKPI[NetWeight_Total])
,ALLEXCEPT(Fact_ShippingKPI,Fact_ShippingKPI[BatchNo])
,Fact_ShippingKPI[OutStockTransactionID] = 0
)
Then put those columns on table as the screenshot. However, two new columns not showing total values in table.
What should I change to have total values for those new columns?
In order to display total values in the table, you should create and use two new measures "netWeight_Shipped" and "NetWeight_notShipped" based on the existing columns, but not two new columns.
-- New measure
NetWeight_Shipped = CALCULATE(
SUM(Fact_ShippingKPI[NetWeight_Total])
,ALLEXCEPT(Fact_ShippingKPI,Fact_ShippingKPI[BatchNo])
,Fact_ShippingKPI[OutStockTransactionID] <> 0
)
-- New measure
NetWeight_notShipped = CALCULATE(
SUM(Fact_ShippingKPI[NetWeight_Total])
,ALLEXCEPT(Fact_ShippingKPI,Fact_ShippingKPI[BatchNo])
,Fact_ShippingKPI[OutStockTransactionID] = 0
)
You should apply aggregation to your column to see the total value below. Look at this image I have added the same column twice and for the first one, there is no total value. But for the second one, there is a total. This is only for the aggregation I applied to the second column but not to the first column-
This might be a strange question and not sure if it is possible to accomplish this with a Power BI table. My goal is to make the total row display the sum of the first row (Operation flag = 1) of every order in a list.
Logically the summarizing total row would produce the below result by summarizing all the rows in the "Manufactured Qty" column. (The below is just a manually created example in Excel to illustrate)
The desired DAX logic should instead produce the below result i.e. summarizing the quantity of every "Order no" with "Operation flag" equal to 1 in the total row.
Best regards,
Rubrix
One way to do this is to use a measure instead of the column. In this measure, use HASONEVALUE to check if the value is for a data row or for the totals row and either return the sum of all rows (for the normal case) or the sum of the rows where Operation flag = 1 (for the totals).
Manifactured Qty Measure =
var allRows = SUM('Table'[Manifactured Qty])
var firstOnly = CALCULATE(sum('Table'[Manifactured Qty]),'Table'[Operation flag] = 1)
RETURN IF(HASONEVALUE('Table'[Manifactured Qty]), allRows, firstOnly)
I'm working with a dataset where I have a Min Value and a Max value and then a sales value.
If the Min value = 100, the max value = 110 and the Sales value equal to 10. Then I have to create a line chart which plots the output of each number between the min and max multiplied by the sales value.
Which looks like below
The goal is to create a line like below
Is there a way of doing this In Power BI via Dax as I am currently creating a mart table with a cursor for each record in the table containing the initial rows which is getting quite large?
You can create a (calculated) table like this:
Expanded_Data =
GENERATE(
'RawData';
SELECTCOLUMNS(
var maxMinusMin = [Max]-[Min]
return
GENERATESERIES(
[Min]*maxMinusMin;
[Max]*maxMinusMin;
maxMinusMin
);
"Plot_Point"; [Value]
)
)
Where 'RawData' is the table name which has at least two columns named [Max] and [Min] :
1
In this way you don't need the sales value info. Just substitute the variable for the sales value column
I am trying to find the maximum route for each day based on the count of cars in PowerBI/DAX.
An example of my data is as follows:
Date Route Count
01-Nov-17 A 10
01-Nov-17 B 5
02-Nov-17 A 2
02-Nov-17 C 22
03-Nov-17 B 2
Hence I want to find the max count of route for each date and display the results of a table like so...
Date Route Count
01-Nov-17 A 10
02-Nov-17 C 22
03-Nov-17 B 2
Any suggestions would be very much appreciated.
Thanks,
Fiona
First, define measure for max car count:
[Max Count] = MAX( Cars[Count] )
If you drop this measure into a pivot against dates, it will show you max car counts per date.
Define second measure:
[Max Routes] =
VAR Period_Max_Count = [Max Count]
RETURN
CONCATENATEX (
FILTER ( Cars, [Max Count] = Period_Max_Count ),
Cars[Route], ","
)
This measure will return a string of routes per date that have max count. You need a list instead of one value because of potential ties - multiple routes might have the same max count per period. It's not in your data example, but just to demonstrate this, I added an extra record for the first date:
The way this measure works:
first, it saves max car count per date into a variable.
second, it filters car table to select only routes that have count equal to max count for the date.
third, it iterates over the filtered table and concatenates route names into a list separated by comma.
Right-click the table choose New quick measure
In Calculation drop-down select Max per category
In Base value field, drag the Count column. In this, the value will be aggregated to Sum by default so instead change it to Max of Count
In Category field, drag the route column
Voila! Magic happens! The measure that is created, when plotted against the axis Route will give Max(Count) per Route.
Here is what the DAX will look like:
Count max per route =
MAXX(
KEEPFILTERS(VALUES('Table1'[route])),
CALCULATE(MAX('Table1'[Count]))
)
(so one can directly use this DAX without wanting to drag but i dont understand the DAX at this moment tbh)
Lucky reference for me:
https://learn.microsoft.com/en-us/power-bi/desktop-quick-measures
Create a calculated column with formula:
MAX = IF(CALCULATE(
MAX(Table1[Count]);
FILTER(
Table1;
Table1[Date] = EARLIER(Table1[Date])
)
) = Table1[Count]; Table1[Route]; BLANK())
Create your table and make a page level filter to show all non-blank values of Table1[MAX].