Power BI Sum cells grouped by same ID - powerbi

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
)

Related

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

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-

How can I concatinate multiple columns of a filtered calculated table for a mesure in DAX?

I am trying to filter a calculated table by a parameter value (created with new parameter) then concatinate several columns and display the result in a card.
Measure =
VAR FTab = FILTER('Toy','Toy'[ID] = 'ID Slider Parameter'[ID Slider Parameter Value])
RETURN
DISTINCT( CONCATENATE(FTab[gender] , FTab[region]))
The error that I am getting is Cannot "find table 'FTab'"
The 'Table' I am working with is a calculated table. I know how to do it in Power Query but not with DAX.
I want to filter the table with the slider and add the measure to a card. The output would be something like "fEast".
You can find my .pbix file here http://filedropper.com/Rz9fLpyz
Use CONCATENATEX() instead:
Measure =
VAR FTab =
FILTER(
'Toy',
'Toy'[ID] = [ID Slider Parameter Value]
)
RETURN
CONCATENATEX(
FTab,
[gender] & [region]
)

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:

Power BI - Comparing data at Row Level and concatenating the respective data in other column for same records

I want to show the consolidated data for similar record in separate column in power bi data.
I have a data with two columns and i want the result like below in third & fourth column
3rd column result nothing but comparing unique id in rows, e.g. 1=2 =false, 2=2=true
4th column result nothing but concatenation of Value column for unique record
could you please help to achieve this in power bi - i want to create custom columns for these two result in data table
We can use CalculatedColumn in DAX:
Result =
CALCULATE(
CONCATENATEX (
CALCULATETABLE ( VALUES('Unique'[Value] ) ),
'Unique'[Value],
", ",
'Unique'[Value],
ASC
), ALL('Unique'[Value])
)
And you Validation may be a measure:
Valid = if(SELECTEDVALUE('Unique'[Value]) = CALCULATE( max('Unique'[Value]), ALL('Unique'[Value])), FALSE(), TRUE())

DAX Grouping Evaluation

In this measure - I'm creating a temp table to group by customer ID and return the year of the min order_date for each customer. I then want to count the # of customers that show up for a given year (basically just a row count).
What I'm struggling to understand is - this formula doesn't seem to look at the SUMMARIZE table within it. If I put year and this measure in a matrix, it counts based on the raw table, not the grouped version built by SUMMARIZE in the formula. Any ideas why it's evaluating this way?
COUNTROWS(
SUMMARIZE(
Orders,
Orders[Customer ID],
"min_order_date_year",
MIN(Orders[Order Date].[Year])))
The formula is OK as per logic you provided to it. You have to clear about both your requirement and what your are writing in your code. Your formula is returning exactly what you are instructing it.
If I understand correct, you simply need the Customer count for the Minimum Year. For say if you have 6 unique customer for Year 2019 and 11 unique customer for Year 2020, you are looking here for value 6 to return by your measure.
Now, what your summarize table actually returning? if you create a separate custom table for the Summarize code only as below, you can see the table will actually hold all your customer name/id in first column and the second column will hole the MIN year available for that customer.
orders_summarize =
SUMMARIZE(
Orders,
Orders[customer id],
"min_order_date_year",MIN(Orders[Order Date].[Year])
)
So basically you have list of all customer in your summarize table. And now your are counting rows of your summarize table which is actually returning the total number of unique customers.
Finally, if you wants customer count for a specific Year (like MIN year), follow these below steps-
Step-1: Create a custom summarized table as below-
store_summarized_table =
SUMMARIZE(
store,
store[Customer ID],
"mindate",MIN(store[Order Date])
)
Step-2: create a measure as-
count_cust_id = COUNT('store_summarized_table'[Customer ID])
Step-3: Now configure your Matrix visuals as shown in the below image. You can also get the output in the image-
To avoid the Physical Table, you can do this below-
Step-1: Create a Custom Column as below-
is_min_year =
// -- keep current row's customer id to a variable
VAR current_cust_id = store[Customer ID]
// -- keep current row's YEAR value to a variable
VAR current_year = store[Order Date].[Year]
// -- find the MIN YEAR from order date for the current row customer id
VAR min_year_current_custommer_id =
CALCULATE(
MIN(store[Order Date].[Year]),
FILTER(
store,
store[Customer ID] = current_cust_id
)
)
// -- check the current row's year is the MIN year of order date for the customer as well or not.
RETURN IF(current_year = min_year_current_custommer_id, 1,0)
OR create a measure as-
is_min_year_measure =
VAR min_order_year_for_current_customer =
CALCULATE(
MIN(store[Order Date].[Year]),
FILTER(
ALL(store),
store[Customer ID] = MIN(store[Customer ID])
)
)
RETURN
IF ( MIN(store[Order Date].[Year]) = min_order_year_for_current_customer, 1,0)
Step-2: Create a Measure as below-
For created Custom Column
count_cust_for_min_year =
CALCULATE(
DISTINCTCOUNT(store[Customer ID]),
FILTER(
store,
store[is_min_year] = 1
)
)
For Created Measure
count_cust_for_min_year =
CALCULATE(
DISTINCTCOUNT(store[Customer ID]),
FILTER(
store,
[is_min_year_measure] = 1
)
)
Now add "Order Date" and measure "count_cust_for_min_year" to your Matrix. The out put will same as below-