Dear stackoverflow, please help!
I'm hoping for some assistance with data processing in Power BI, either using Power Query or DAX. At this point I am really stuck and can't figure out how to solve this problem.
The below table is a list of sales by Product, Month, and Year. The problem with my data is that the value in the sales data is actually cumulative, rather than the raw figure of sales for that month. In other words, the figure is the sum of the number of sales for the month (for that Year and Product combination) and the number of sales for the preceding month. As you will see in the table below, the number gets progressively larger in each category as the year progresses. The true number of sales for TVs in Feb of 2021, for example, is the sales figure of 3 minus the corresponding figure for sales of TVs in Jan of 2021 (1).
I really would appreciate if anyone knows of a solution to this problem. In reality, my table has hundreds of thousands of rows, so I cannot do the calculations manually.
Is there a way to use Power Query or DAX to create a calculated column with the Raw Sales figure for each month? Something that would check if Product and Year are equal, then subtract the Jan figure from the Feb figure and so on?
Any help will be very much appreciated,
Sales Table
Product
Sales (YTD)
Month
Year
TV
1
Jan
2021
Radio
4
Jan
2021
Cooker
5
Jan
2021
TV
3
Feb
2021
Radio
5
Feb
2021
Cooker
6
Feb
2021
TV
3
Mar
2021
Radio
6
Mar
2021
Cooker
8
Mar
2021
TV
5
Apr
2021
Radio
7
Apr
2021
Cooker
8
Apr
2021
TV
7
May
2021
Radio
8
May
2021
Cooker
8
May
2021
TV
9
Jun
2021
Radio
10
Jun
2021
Cooker
10
Jun
2021
TV
10
Jul
2021
Radio
10
Jul
2021
Cooker
10
Jul
2021
TV
11
Aug
2021
Radio
13
Aug
2021
Cooker
12
Aug
2021
TV
11
Sep
2021
Radio
13
Sep
2021
Cooker
12
Sep
2021
TV
12
Oct
2021
Radio
14
Oct
2021
Cooker
13
Oct
2021
TV
17
Nov
2021
Radio
19
Nov
2021
Cooker
17
Nov
2021
TV
19
Dec
2021
Radio
20
Dec
2021
Cooker
20
Dec
2021
TV
4
Jan
2022
Radio
2
Jan
2022
Cooker
3
Jan
2022
TV
5
Feb
2022
Radio
3
Feb
2022
Cooker
5
Feb
2022
Thanks, Jim
Give this a try in powerquery / M. It groups on Product and Year, then sorts the months, and subtracts each row from the next row to determine the period amount.
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Grouped Rows" = Table.Group(Source, {"Product", "Year"}, {
{"data", each
let r=Table.Sort(Table.AddIndexColumn(_, "Index", 0, 1),{ each List.PositionOf({"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}, [Month]), {"Month",Order.Ascending}}),
x= Table.AddColumn( r, "Period Sales", each if [Index]=0 then [#"Sales (YTD)"] else [#"Sales (YTD)"]-r{[Index]-1}[#"Sales (YTD)"])
in x
, type table }
}),
#"Expanded data" = Table.ExpandTableColumn(#"Grouped Rows", "data", {"Sales (YTD)", "Month", "Period Sales"}, {"Sales (YTD)", "Month", "Period Sales"})
in #"Expanded data"
Related
I have a calendar table where I created with M.
I'm relating it to a table of activities, where I grouped it by week.
I've calculated the total value of activities I have in that time period by a DAX measure (let's consider 5000), I need to plot a linear descending line over the period from that value (5000) to 0.
I've managed to get close results, but it doesn't stay at 0. It either exceeds or is missing 1 period of time.
Here is the current table and the expected table:
Year
Month
End of Week
Expected
2021
6
05/06/2021
2021
6
12/06/2021
2021
6
19/06/2021
2021
6
26/06/2021
2021
7
03/07/2021
2021
7
10/07/2021
2021
7
17/07/2021
2021
7
24/07/2021
2021
7
31/07/2021
2021
8
07/08/2021
2021
8
14/08/2021
2021
8
21/08/2021
2021
8
28/08/2021
2021
9
04/09/2021
2021
9
11/09/2021
2021
9
18/09/2021
2021
9
25/09/2021
2021
10
02/10/2021
2021
10
09/10/2021
2021
10
16/10/2021
2021
10
23/10/2021
2021
10
30/10/2021
2021
11
06/11/2021
2021
11
13/11/2021
2021
11
20/11/2021
2021
11
27/11/2021
2021
12
04/12/2021
2021
12
11/12/2021
2021
12
18/12/2021
2021
12
25/12/2021
2022
1
01/01/2022
2022
1
08/01/2022
2022
1
15/01/2022
2022
1
22/01/2022
2022
1
29/01/2022
2022
2
05/02/2022
EXPECTED TABLE
Year
Month
End of Week
Expected
2021
6
05/06/2021
5000
2021
6
12/06/2021
4857,143
2021
6
19/06/2021
4714,286
2021
6
26/06/2021
4571,429
2021
7
03/07/2021
4428,571
2021
7
10/07/2021
4285,714
2021
7
17/07/2021
4142,857
2021
7
24/07/2021
4000
2021
7
31/07/2021
3857,143
2021
8
07/08/2021
3714,286
2021
8
14/08/2021
3571,429
2021
8
21/08/2021
3428,571
2021
8
28/08/2021
3285,714
2021
9
04/09/2021
3142,857
2021
9
11/09/2021
3000
2021
9
18/09/2021
2857,143
2021
9
25/09/2021
2714,286
2021
10
02/10/2021
2571,429
2021
10
09/10/2021
2428,571
2021
10
16/10/2021
2285,714
2021
10
23/10/2021
2142,857
2021
10
30/10/2021
2000
2021
11
06/11/2021
1857,143
2021
11
13/11/2021
1714,286
2021
11
20/11/2021
1571,429
2021
11
27/11/2021
1428,571
2021
12
04/12/2021
1285,714
2021
12
11/12/2021
1142,857
2021
12
18/12/2021
1000
2021
12
25/12/2021
857,1429
2022
1
01/01/2022
714,2857
2022
1
08/01/2022
571,4286
2022
1
15/01/2022
428,5714
2022
1
44583
285,7143
2022
1
44590
142,8571
2022
2
44597
0
It is recommended that I remove the decimal places from the visualization of the graph of the linear line. However, I will not round the value for the line to be straight down.
I have a table of values for orders per month by region that looks like this:
Orders Table
Orders (YTD)
Month
Year
1
Jan
2021
4
Feb
2021
4
Mar
2021
5
Apr
2021
14
May
2021
16
Jun
2021
17
Jul
2021
19
Aug
2021
22
Sep
2021
24
Oct
2021
34
Nov
2021
35
Dec
2021
1
Jan
2022
3
Feb
2022
4
Mar
2022
Along with a table that orders the months in sequence as below, that will be modelled to order the months in the first table so that they appear in sequence in graphs.
Monthly Sequence Table
Month Sequence
Month
1
Jan
2
Feb
3
Mar
4
Apr
5
May
6
Jun
7
Jul
8
Aug
9
Sep
10
Oct
11
Nov
12
Dec
Upon closer inspection of my data, I have realised that the number of orders per month are not the raw figure per month, but a cumulative total for every order in the calendar year so far (new orders for month + orders for preceding month). Firstly, I want to calculate the correct sum of orders per year, which should actually just be the MAX month from the orders table. Of course in most years this will be December, but for the current year it needs to be the latest month. I wanted to use a measure to calculate the MAX 'Monthly Sequence Table'[Month Sequence] number from each table, by year. I thought maybe a filter function would be used but could not work out exactly how to do this in DAX.
Secondly, and similarly, I want to calculate the actual number of orders per each individual month using DAX. In this case, I want to take the Orders (YTD) total for that month/year combination and subtract it from its immediately preceding month. What would the formula look like for this?
Thanks in advance.
There are many method of having a measure to show percentage in a column of table ,
but cannot find a method to always show the ratio of a SPECIFIC group in percentage between two category.
data sample:
YEAR MONTH TYPE AMOUNT
2020 Jan A 100
2020 Feb A 250
2020 Mar A 230
2020 Jan B 158
2020 Feb B 23
2020 Mar B 46
2019 Jan A 499
2019 Feb A 65
2019 Mar A 289
2019 Jan B 465
2019 Feb B 49
2019 Mar B 446
2018 Jan A 13
2018 Feb A 97
2018 Mar A 26
2018 Jan B 216
2018 Feb B 264
2018 Mar B 29
2018 Jan A 314
2018 Feb A 659
2018 Mar A 226
2018 Jan B 469
2018 Feb B 564
2018 Mar B 164
My Goal is always show the percentage of A compare with the total amount
YEAR and MONTH are used to synchronize with slicer.
e.g. I select YEAR = 2020 , MONTH = Jan
100/258 = 38%
Manually inputted in textbox
First, Create these following 3 measures in your table-
1.
amount_A =
CALCULATE(
SUM(pie_chart_data[AMOUNT]),
FILTER(
ALLSELECTED(pie_chart_data),
pie_chart_data[TYPE] = "A"
)
)
2.
amount_overall =
CALCULATE(
SUM(pie_chart_data[AMOUNT]),
ALLSELECTED(pie_chart_data)
)
3.
amount_A_percentage = [amount_A]/[amount_overall]
Now, add both measure amount_A and amount_overall to your donut chart's values column. And place the amount_A_percentage measure to a Card and place the card in center of the Donut chart. The presentation will be as below finally-
I have an Orders fact table and a connected Date dimension.
I'd like to create a running total measure by year and month, but for the current year I only want it to total up to the current date and then be blank afterwards. I'll be turning it into a bar graph and I don't want the plateau that will happen as it calculates each month that hasn't happened yet as the current YTD value.
I'm coming from a SQL background where this would be an easy task, but seems difficult in power bi/dax.
I'm currently working with the following dax:
SalesRT_NEW =
IF (
MONTH ( TODAY () ) <= MAX ( DimDate[Date] ),
TOTALYTD ( SUM ( 'FactOrderDetails(3yr)'[LineTotal] ), DimDate[Date] ),
BLANK ()
)
Output (as table for testing) is (starting from June for brevities sake):
YEAR Month SalesRT
2017 Jun 1500
2018 Jun 1750
2019 Jun 1900
2017 Jul 1650
2018 Jul 1858
2019 Jul 2050
2017 Aug 1800
2018 Aug 1965
2019 Aug 2050
Desired output:
YEAR Month SalesRT
2017 Jun 1500
2018 Jun 1750
2019 Jun 1900
2017 Jul 1650
2018 Jul 1858
2019 Jul 2050
2017 Aug 1800
2018 Aug 1965
2019 Aug
Got the answer:
IF(MAX(DimDate[Date]) <= today() || MONTH(MAX(DimDate[Date])) = Month(today()),TOTALYTD([SalesTotal], DimDate[Date]), BLANK())
I am using Area chart by google visualisation. I need to customise the x-axis values.for example the date starts from 1 oct to 2 dec. In this I need to display only 10 values which includes the start date and the end date.
By default it displays like this.
oct 1 oct 2 oct 3 oct 4 oct 5 oct 6 oct 7 oct 8 oct 9 oct 10
But I need in this format.
oct 1 oct 7 oct 14 oct 21 oct 28 nov 4 nov 11 nov 18 nov 25 dec 2
and the values in between i.e., from start date to end date can be anything.
Any suggestions?
Thank you in advance
You can do one thing. Get input the start date and end date well then calculate its difference. After getting the difference divide it in 10 intervals. Then assign these 10 intervals to the x-axis value.