Generating multple rows from one row - powerbi

I have a datasource in powerbi with the following format:
Sale# Date Value Installments
1 Jan/2020 150,00 2
2 Mar/2020 210,00 3
Then Installments column is the number of payments the sale will be divide. I need to transform the above datasource in one line for each payment, So if the first one has two installments, the payment will be divided in two months:
Sale# Date Value
1 Jan/2020 75,00
1 Feb/2020 75,00
2 Mar/2020 70,00
2 Apr/2020 70,00
2 May/2020 70,00

You can do this in Power Query following these below steps-
Step-1: Add a custom column to your table as shown below-
This will generate a list per row.
Step-2: Expand the list as shown below (right click on the New column)-
You have now data as below-
Step-3 Add a custom column as shown in the below image for incremental date-
Step-4 Add another custom column as shown in the below image for equal installment amount-
Step-5 You will have this below data now. Just remove Yellow marked columns and you will get your final desired output.

Related

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

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]))

Group 10 columns of data to gain distinct count of rows Power BI

I'm trying to display all of the distinct values within this table (there are many other columns in this table) and show how many rows each distinct value shows in.
I have tried to use group by but this does not work. It needs to be filterable by country from another column but i can do that by page filter.
I am trying to show what the top 5 associations are in terms of appearance.
enter image description here
Put the 10 columns in a Table visual. Then create this measure and add it too. Then sort descending on Distinct.
Distinct = COUNTROWS('Your Table Name')
To see only the Top 5, go to the Filter pane, and pick the first column and set the Filter type to Top N, and then Top 5 by the Distinct measure.

Order date in a table

Hi I'm trying to order a table in BI by monthNumber, but now I have same months in differents year, and PowerBI doesn't care about that. I have:
Jan-20
Feb-19
Feb-20
Mar-19
Mar-20
Apr-19
May-19
Jun-19
Jul-19
Aug-19
Sep-19
Oct-19
Nov-19
Dec-19
And I want:
Feb-19
Mar-19
Apr-19
May-19
Jun-19
Jul-19
Aug-19
Sep-19
Oct-19
Nov-19
Dec-19
Jan-20
Feb-20
Mar-20
NOTE: Each month I will add a new month (The actual current month e.g. Now Aug-20) and this should still work properly
Let your table name is "order_by_month" and the column name is "month_year". Now just follow this following steps to order data as per your requirement.
Step-1: In Power Query, create a custom column as below image-
We are generating this column with the First date of each month so that we can order our original data later based on the Date value. The generated value in the new column will look like below-
Step-2: Change the above red marked column's data type as Date.
Step-3: Get back to report by clicking the "Close & Apply" Button.
Step-4: In the report, go to Table view and select your original column "month_year" and order this column by newly created column "date_formatted_value" as shown in the beloe image.
Now the final output will be sorted as below as you wants-

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.

Conditional Format top 2 rows of a table visual power BI

I have a table visual with a date column and I have a requirement to highlight the top 2 rows. The data on the table visual is sorted desc by the date column.
I need help to conditional format the background color for the top 2 rows.
I tried searching for a way to do this but no luck.
You can calculate the rank of the rows and use conditional formatting to highlight the top 2 rows. But first, we need to define what "top 2 rows" means. You said it is sorted by date descending, so I will assume that "top 2 rows" means the rows with the 2 biggest dates. I will use a measure, which will respond to filters applied on the data. Then we will highlight the rows with rank 1 and 2 (assuming dates are unique in table's rows).
Make new measure like this:
Measure = RANKX(ALLSELECTED('Table'); CALCULATE(SELECTEDVALUE('Table'[Date])))
Where Table is your table name, and Date is the name of the date column. This will give you a number (1, 2, 3...) where 1 is the row with the biggest date, 2 is the second biggest date, and so on.
Then for every field shown in your table, add the following background color condition (right click each item in the list of fields and select Conditional formatting -> Background color):
Set Format by to be Rules, select your measure in Based on field and ad condition > 0 and <= 2 to set the desired background color. Repeat this for all fields shown.