Power BI DAX - using monthly totals instead of grand totals - powerbi

I'm having issues with the following calculation:
"Kunden Anzahl" refers to the number of customers via distinct count, with %SG being the percentage. The issue is that Power BI is taking the grand total of 21.801 for the calculation of the percentages instead of the corresponding total of each month (19.337 for 12/2020, 21.391 for 12/2021). This results in the total percentage being less than 100% except for 01/2022.
So what it should do is divide each customer count by the total of its corresponding month - for example 6.326 / 19.337 = 32.7%
I've tried grouping the denominator by month and ignoring the categories by using REMOVEFILTERS but this just replicates the first column.
Any help is greatly appreciated!
Reference to comment:
Data model looks like this - JJJJMM is connected to a date table:

Assuming your data looks like this
CustomerID
Category
Month
14
A
01 January 2021
21
A
01 January 2021
29
B
01 January 2021
39
B
01 January 2021
6
B
01 January 2021
18
C
01 January 2021
34
A
01 February 2021
29
A
01 February 2021
4
A
01 February 2021
17
B
01 February 2021
24
B
01 February 2021
39
B
01 February 2021
11
B
01 February 2021
1
B
01 February 2021
42
A
01 March 2021
46
A
01 March 2021
2
A
01 March 2021
30
B
01 March 2021
DAX Calculation
CountDistinct (%) =
VAR CurrentValue =
DISTINCTCOUNT ( 'Table'[CustomerID] )
VAR AllMonth =
CALCULATE (
DISTINCTCOUNT ( 'Table'[CustomerID] ),
ALL ( 'Table' ),
VALUES ( 'Table'[Month] )
)
RETURN
DIVIDE ( CurrentValue, AllMonth )
Output
Reference
https://www.sqlbi.com/articles/using-allexcept-versus-all-and-values/

Related

What DAX will calculate amount for same month in last months report?

I am struggling to work out the correct DAX measure to sum amount for the same period (e.g. month) but from a previous report.
Full Year forecast reports are provided monthly with a Report Date of EOMONTH for the month provided. These contain Amounts for each month in the year (called Period End Date, also dated EOMONTH). These are imported to a "Forecasts" table.
The following sample table replicates data from 3 separate monthly forecast reports, but rows are limited only to Jan-Mar months for simplicity (note - I have created Amounts based on concatenated month numbers for Report Date & Period End Date, for ease of identifying correct amounts in expected results):
Report Date
Period End Date
Amount
31 Jan 22
31 Jan 22
11
31 Jan 22
28 Feb 22
12
31 Jan 22
31 Mar 22
13
28 Feb 22
31 Jan 22
21
28 Feb 22
28 Feb 22
22
28 Feb 22
31 Mar 22
23
31 Mar 22
31 Jan 22
31
31 Mar 22
28 Feb 22
32
31 Mar 22
31 Mar 22
33
There is a "Dates" table, relationship = Dates[Date] to Forecasts[Period End Date], 1 to many, single direction. The user selects a single Report Date via a slicer creating filter context, visuals categories use Forecasts[Period End Date] for row context.
I've tried various methods but so far am unsuccessful, I'm having a mind meld and am probably overthinking this and therefore not looking at best method. One DAX example is:
Prev Month Forecast =
VAR _SelRptDate = SELECTEDVALUE( 'Forecasts'[Report Date] )
VAR _PreRptDate = EOMONTH( _SelRptDate, -1)
VAR _Result =
CALCULATE(
SUM( 'Forecasts'[Amount] ),
FILTER( 'Forecasts', 'Forecasts'[Report Date] = _PreRptDate)
)
RETURN _Result
Ideally I'd like to use an appropriate time intelligence function if one works for this. Happy to create inactive relationships if needed (e.g. Dates[Date] to Forecasts[Period End Date]). Preferably a Measure, not calculated column.
The following examples demonstrate expected results based on Report Date selected by the user:
Report Date = 28 Feb 22
Period End Date
Amount
Amount in Previous Report Date for Same Period End Date
31 Jan 22
21
11
28 Feb 22
22
12
31 Mar 22
23
13
Report Date = 31 Mar 22
Period End Date
Amount
Amount in Previous Report Date for Same Period End Date
31 Jan 22
31
21
28 Feb 22
32
22
31 Mar 22
33
23
Really appreciate any help / direction.
Thanks

Power Query/DAX to calculate monthly raw sales figure

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"

How can I create a dynamic measure or column for an array in PowerBI?

Excel Example
I am attempting to recreate a similar chart in PowerBI as I did in excel seen below:
Here I have revenue per day. The chart shows the percent of days where revenue exceeds a fixed amount (100, 200, etc).
In PowerBI I know how to recreate the table that the chart is based on by defining a column, but it's not dynamic. I can't apply filters to change the column values.
I know I can apply filters to measures but when I try to replicate the formula as a measure I get an error, which I assume is due to the formula trying to return an array of values.
Here is my formula for the fixed column version:
table2 column = countx(
filter(
DayRevenueTable,
[Revenue]>Table2[DayRevenueExceeding])
,[Day])
/Total
Assuming your table looks like this:
Date
Revenue
04 January 2022
102
11 January 2022
162
17 January 2022
180
02 January 2022
185
12 January 2022
203
05 January 2022
278
01 January 2022
353
16 January 2022
449
14 January 2022
500
06 January 2022
515
08 January 2022
582
10 January 2022
600
03 January 2022
618
09 January 2022
626
13 January 2022
626
15 January 2022
706
18 January 2022
765
07 January 2022
895
You need to first create a table with your fixed values. Basically is the same concept as creating a parameter.
Using that table as a reference, you can create your calculation around Fixed Values[Value].
DAX: Fixed Values
Fixed Values = GENERATESERIES(100,1000,100)
DAX: Days When Revenue Exceeds Amount
Days When Revenue Exceeds Amount =
VAR CurrentFixedValue =
SELECTEDVALUE ( 'Fixed Values'[Value] )
VAR CountValues =
CALCULATE (
COUNTROWS ( 'Table' ),
'Table'[Revenue] < ( CurrentFixedValue + 100 )
)
VAR AllValues =
CALCULATE ( COUNTROWS ( 'Table' ), ALLSELECTED ( 'Table' ) )
VAR Calc =
DIVIDE ( CountValues, AllValues )
RETURN
Calc
Output

How to count number of projects that got approved or the status changed in DAX

I have a data set that looks like below. The data is about project ideas that are raised in our company. The project ideas will be kept in Backlog section first and then moved to Do Next once then get approved. The modified date is a date when the project idea reviewed and approved or the status changed to Do Next. If it is not approved, then it remains in Backlog.
Id Modified Date Created Date Status
1 8/4/2017 8/4/2017 Backlog
2 6/10/2021 6/10/2021 Backlog
3 3/5/2018 3/5/2018 Backlog
1 6/5/2020 8/4/2017 Do Next
1 30/5/2021 3/5/2020 Analyze
2 5/4/2022 6/10/2021 Do Next
2 8/8/2022 6/10/2021 Analyze
What I want to achieve is that, I want to count how many projects moved from Backlog to Do Next status using DAX function or approved. So this time, for example I have two projects that moved from Backlog to Do Next (Id1 and Id 2). I am relatively new to DAX. Can anyone please help me on this?
I have modified your table to add an "orphan" Do Next Status, as the last row, to test the count dependency on the previous Status Backlog.
Assuming your table look like this
Table
Id
Modified Date
Created Date
Status
1
08 April 2017
08 April 2017
Backlog
2
06 October 2021
06 October 2021
Backlog
3
03 May 2018
03 May 2018
Backlog
1
06 May 2020
08 April 2017
Do Next
1
30 May 2021
03 May 2020
Analyze
2
05 April 2022
06 October 2021
Do Next
2
08 August 2022
06 October 2021
Analyze
4
09 August 2022
06 October 2021
Do Next
Calculation
Count Projects =
VAR BacklogProjects =
SUMMARIZE ( FILTER ( 'Table', [Status] = "Backlog" ), [Id] )
VAR DoNextProjects =
SUMMARIZE ( FILTER ( 'Table', [Status] = "Do Next" ), [Id] )
VAR SameProjects =
INTERSECT ( BacklogProjects, DoNextProjects )
VAR Result =
COUNTROWS ( SameProjects )
RETURN
Result
``

How to have a measure always show the ratio as percentage in scorecard/textbox POWER BI

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-