Dax measure (add new columns) not showing total in table - powerbi

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-

Related

Running MAX of values in another column in DAX

I'm working on having a column whose values are the running MAX of another column.
My main table has three columns and I use the summarize function to virtually add another column named as SUM OF EACH DATETIME to the summarized table. Now I want to have the running MAX of the SUM OF EACH DATETIME column in the summarized table in another new column as MAX of Sum column. My table and its preferred columns are shown below:
I'd appreciate it if you kindly guide me how can I have the MAX of Sum column in my summarized table.
I should note that the formula to calculate the SUM OF EACH DATETIME column is:
SUMMARIZE(TABLE, TABLE[DateTimeStamp],
"SUM OF EACH DATETIME", IF(COUNTROWS(TABLE)=calculate(DISTINCTCOUNT(TABLE[Name]), ALLSELECTED()),SUM(TABLE[Value]),BLANK()))
You can create one measure and one column as given below.
Column:
date_sum_column =
var current_row_date_time = ('your_table_name'[DateTimeStamp])
return
CALCULATE(
SUM('your_table_name'[Value]),
FILTER(
ALL('your_table_name'),
'your_table_name'[DateTimeStamp] = current_row_date_time
)
)
Measure:
running_max_sum =
CALCULATE(
MAX(your_table_name[date_sum_column]),
FILTER(
ALL(your_table_name),
your_table_name[DateTimeStamp] <= MIN(your_table_name[DateTimeStamp])
)
)
Here is the output:

PowerBi Distinctcount not working properly with 3 measures

I am having an issue using the Distinctcount function in DAX. I have a table with a total of 1,154,493 rows. I have a measure created to count the number of distinct values in column 1. I have another measure created to count the number of distinct values in column 1 with filters. I have a 3rd and final measure created to count the number of distinct values of column 1 with different filters. The issue I am running into is the count of measure 2 + measure 3 should equal measure 1 however added together they are GREATER than the value of measure 1 which is just a grand total. How is this possible? Unfortunately I can't share the table but below is the code I am using for the two measures:
Measure1=distinctcount('Table1'[Column1])
Measure2=calculate(distinctcount('Table1'[Column1]),'Table1'[CTest] = 1,'Table1'[CTest2] = "07")
Measure3=calculate(distinctcount('Table1'[Column1]),'Table1'[CTest] = 2,'Table1'[CTest2] = "07")
I am at a loss. Thank you in advance!!
For troubleshooting you should identify values of Column1 with Measure2 and Measure3 > 0, those are being added twice.

Power BI DAX measure calculation

Step1:
I have created a calculated table containing Level, Location, L2code from level sales data. I need to create a report that will count rows based on the level1 group.
Note that there are more levels in the table. This is only an example of one of the levels.
How can I count the rows for each level1?
Step2:
I need to create all combinations of counts based on location and l2 code and count the numbers.
like in example 2 location and 8 distinct l2code so it should be 2*8 =16 total possible rows.
How can I achieve this using the DAX measure?
Source data file
Output report
first one is a simple measure as below-
DistinctRowCount = Count(your_table_name[Level1])
Second one is bit tricky and you can try this below measure-
CrossCount =
var distinct_location =
calculate(
distinctcount(your_table_name[Location]),
allexcept(
your_table_name,
your_table_name[Level1],
your_table_name[Location]
)
)
var distinct_l2code =
calculate(
distinctcount(your_table_name[l2code]),
allexcept(
your_table_name,
your_table_name[Level1],
your_table_name[Location],
your_table_name[l2code]
)
)
return distinct_location * distinct_l2code
Sample output-

How to get a max of a measure?

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:

Power BI Sum cells grouped by same ID

How can I make a formula which sums all the cells which have the same ID?
Edit: Both of these columns are in the same table. I need a new column which calculates the sum of all the hours with the same ID.
In that case, I would create a new summery table:
SummeryTable =
SUMMARIZE(
'TableName';
'TableName'[ID];
"Time_summed"; SUM('TableName'[TimeColumn])
)
Then you will end up with a table with distinct [ID] on each row and the sum of all hours corresponding to this ID from the original data table. Which you can use to create a relationship with the original table.
EDIT_1:
Yes you can if you use a calculated column like this:
SumTime =
VAR thisID = [ID]
RETURN
CALCULATE(
SUM('TableName'[TimeColumn]);
ALL('Tablename');
'TableName'[ID] = thisID
)