How to dynamically add rows to column in power bi/power query - powerbi

I'm facing a challenge in power bi where I need to join Table 1 & Table 2 but the catch is Table 2 needs to be pivoted before joining.
Input:
Table 1
Table 2
Expected Output:
How to build the output table when the Table 2 rows will be increasing daily

Your desired result needs a combination of Unpivot, Merge and Pivot steps.
You can follow the following steps:
Convert the Date column to Text type.
Unpivot columns Sales in KG & Sales in Amount from Table 2 - it will create 2 columns called Attribute & Value
Merge columns Date & Attribute to create a new column (lets call it columnHeaders) - this will be in the format - 1/3/22 Sales in KG, 1/3/22 Sales in Amount ...
Merge Table 1 into Table 2 and expand the Product Name column
Now you will have 4 columns - Product Code, columnHeaders, Value, & Product Name
Pivot columnHeader using the Value column for values
You should have your desired result.

I dont know why you try to unpivot your table. Just use a Matrix visualization:
Model relationship:
Imput data + output:
sum of kg = CALCULATE(sum(Table2[Sales in kg]))

Related

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

I have 2 tables in PowerBI.
Table 1:
Table 2:
I have the sales target for each month in Table 1 and also the actual sales that I achieved in Table 2. May I know how should I create another column in Table 1 where it sum all the sales from Table 2 based on respective months? The expected output will be something like this:
Expected output:
Any help or advise will be greatly appreciated!
Here's one potential solution:
Summarize table two so that it groups the total sales by month. You can do this by grouping on the month in power query, or using a dax function like SUMMARIZE.
Create your new column in table 1 using the LOOKUPVALUE function. It will look something like this LOOKUPVALUE(Total Sales, Date, Month & Yrs).
Make a relationship between Table 1 and Table 2 using "Month & Yrs" and "Date".
Then it's just a matter of adding a table with "Month & Yrs" as rows, and "Sales Target" and "Sales" as values. You can then just rename if you want.
I'd recommend using a calendar dimension as a general rule. Much easier to make relationships, add columns etc.

how to get Distinct count based on the condition in power bi

I have table name called Data. in this table have a two column Product ,QTY
Now I have created new measure for DISTINCT Value for QTY column
Distict Count Qty = CALCULATE(DISTINCTCOUNT(Data[Qty]))
Now Table looks like after added above measure
from above table I want to get count for three conditions form Distinct Count Qty measure.
if values have < 4 and if values have => 4 , if value have =12 .
this three count I want from distinct value measure .

Power BI DAX data from 2 tables

I have 2 tables see image
And I want to get total revenue for Store ABC only for product "ID1" so in this simple tables the final Revenue should be 251.
So I should filter only "ABC" in first table and filter only "ID1" in the second and then add column "Revenue" to the first table with the key "email" and then SUM revenue, but I got completely lost how to write it in DAX
Any suggestions?
Thanks
Lukas

Power BI How to Sum Matched 2 Columns

I have two tables. First one represents sales values of company by department, product ID and month. Second table contains sales target by department and month. I want to add a column to second table. It should shows sum of values from table 1 with grouping department and month.
For Example:
For 310101 in Februray sum of values is 110. So, the first row of table 2 should be 110.
Can you please help me with this DAX function?
Create a calculated column in both tables which will represent an unique ID (Eg: ID = Table1[Dpt ID] & Table1[Month]) and join the both tables by this ID field to create a relationship between these 2 tables.
Now, select all the columns from Table 2 and also select Value column from Table 1. You should get the sum by department.

How to do countifs in powerbi

I want to do countif in PowerBI (Example: count of total item with condition #1: having transaction of 2 or more, condition #2: year)
I have sample data comprised of PO (transaction) #, item #, date (year), item description, ship to location.
I can achieve the result through Excel - Pivot a matrix table of rows of items, columns of year and the value is count of PO/transactions. A separate table on the side is utilized to count the total item within Column (Years) that has transaction count > 2.
I can't figure out what DAX to use in PowerBI to achieve the same thing as I could with Excel:
Sample of transaction counts:
Usually COUNTIFS in Excel are implemented by use of CALCULATE(<expression>,<filter1>,<filter2>…) in Power BI, for example:
CALCULATE(SUM(Table1[Column1]), FILTER(Table1, Table1[Column1] < Table1[Column2]))
Read more details here.