How to create a table from another table in PowerBI and Sum a column

kukulu

I have a three tables that looks like this:


|season| production|      
|:------|:---------|
| A    | 12        |
| A    | 200       |
| A    | 40        |
| A    | 60        |


|season| production|      
|:------|:---------|
| B    | 11        |
| B    | 20        |
| B    | 400       |
| B    | 600       |


|season| production|      
|:------|:---------|
| C    | 119       |
| C    | 212       |
| C    | 466       |
| C    | 697       |

I want to have a table like this:


|seasons| Total_prodtn| Percentage_Prodtn|
|:------|:------------|:-----------------|
| A     |sum from A   | %                |
| B     |sum from A   | %                |
| c     |sum from c   |  %               |

I tried using DAX but it did not workout.

any better way to do this?

Mik

Solution 1 :

VAR t1=Row("season",VALUES(Table1[season]),"Total_prodtn",SUM(Table1[production]))
VAR t2=Row("season",VALUES(Table2[season]),"Total_prodtn",SUM(Table2[production]))
VAR t3=Row("season",VALUES(Table3[season]),"Total_prodtn",SUM(Table3[production]))
VAR uni=UNION(t1,t2,t3)
RETURN 
    ADDCOLUMNS(
        uni
        ,"Percentage_Prodtn",MROUND(DIVIDE([Total_prodtn],Sumx(uni,[Total_prodtn]))*100,2)
    )

Solution 2:

VAR allInOne =UNION(Table1,Table2,Table3)
        
VAR withTotal =
    ADDCOLUMNS(
        SUMMARIZE(allInOne,[season])
        ,"Total_prodtn",VAR s=[season] 
                        RETURN
                            SUMX(
                                FILTER(allInOne,[season]=s)
                                ,[production]
                            )
    )
RETURN 
    ADDCOLUMNS(
        withTotal
        ,"Percentage_Prodtn",DIVIDE([Total_prodtn],SUMX(allInOne,[production]))
    )

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Mysql from sum one table column subtract sum of another table column

How to create a computed column that references another column from another table?

How to create table from another table with passing NULL values to a column?

How to sum column values from two tables and preserve another column which is only in one table

How to select a column from a table and another column from another table

Create column from another table dynamically

Updating column in table with sum of another table

How to count the difference between number from one cell and SUM of the column from another table

How to sum a column where another column is equal to other table

PowerBI - Match Value from another table

create an empty table which gets the column names from another table

Subtract the sum of one column from another table's column

How to create table in Hive with specific column values from another table

Update column with SUM from another table, PostgreSQL

Subtract value of one table from another in PowerBI

How to Update Column from a Column in another table

Create table with column names from fields of another table

How to update table from another table with sum function?

how to get the sum of a child column from another table

Create Table Column From Another Vector

How do I create a new table with one column from another table in SQL?

How to create a MySQL trigger for updating a sum of a table with data from a field in another table after an on Insert or Update

How to create another column in python pandas from the current table?

How to add a new column with custom values, based on a WHERE clause from another table in PowerBi?

Convert data in Table from Row to Column in PowerBi

How to create a column in table where the value come from the summation of another column in another table

How to sum a column from a query created table

How to conditionally format a column based on Min and Max targets from another table in PowerBI?

How to create a column that has the count from one table of values in another?