POWER BI : Running Total without Date column and ID Column - powerbi

I have a table with just 2 columns i.e Location and Number of assessments and I want to find the Running total for the total number of assessments.
In the Image Number of Assessments By Location , you can see that the running total (247) is appearing but with every Location. I just want a single bar at the end displaying 247 (not 741). I have used the SUM function on the Assessment in DAX
DATA :
Location
Assessments
CA
118
AT
54
MT
33
AN
23
CH
17
RM
2

In order for you to achieve what you need, You need a derived tabular dataset which contains "Total" of all the Location.
You can create a derived table like this
Table =
VAR _tbl =
UNION ( //step3-appending subTbl1 to subTbl2
ADDCOLUMNS (
DATATABLE ( "Local", STRING, { { "Total" } } ), //step1- creating a table that contains the total of all the locations --subTbl1
"Value", SUMX ( t1, t1[Assessments] )
),
SELECTCOLUMNS (
t1,
"Local", t1[Location],
"Value", CALCULATE ( SUM ( t1[Assessments] ) ) //step2-creating a table that contains the total of all the locations by location -- subTbl2
)
)
RETURN
_tbl
Once you have that, you can plot the data points like this

Related

Power BI, Line Chart with Base Value 100

I need to build a line chart that is supposed to show the cumulative increase from Day 1 to the End.
An Example would be like this:
Date Capital Value
31-Jan 237 100.00
28-Feb 250 105.48
31-Mar 210 88.60
30-Apr 300 126.58
In other words, is dividing every value by the first value, not of the whole table but the dates that are been displayed in the chart. The first date is dynamically changed as time passes, making it impossible to fix the formula to 31-Jan for example
Kind Regards
Try this measure:
% Capital running total in Date =
VAR runtotal =
CALCULATE (
SUM ( 'YourTable'[Capital] ),
FILTER (
ALLSELECTED ( 'YourTable'[Date] ),
ISONORAFTER ( 'YourTable'[Date], MAX ( 'YourTable'[Date] ), DESC )
)
)
VAR baseval =
CALCULATE (
SUM ( 'YourTable'[Capital] ),
FIRSTDATE ( ALL ( YourTable[Date] ) )
)
RETURN
DIVIDE ( runtotal, baseval )
Note that for calculating the Running Total Power BI can help you with a Quick Measure.

Unexpected result of measure from filtering table with dynamic criteria in Power BI

I have a table called DW_XYZ:
Year
Month
Type
Value
2021
1
A
10
2021
1
B
12
2021
2
A
20
*no data for type B in Month=2
I would like to create a measure that stores data that I already filtered by last month of data stored in DW_XYZ with dax formula:
CALCULATE(
SUM(DW_XYZ[Value]),
FILTER(DW_XYZ,DW_XYZ[Month]=
CALCULATE(MAX(DW_XYZ[Month]),
FILTER(DW_XYZ,DW_XYZ[Year]=
MAX(DW_XYZ[Year]))) && DW_XYZ[Year]=MAX(DW_XYZ[Year]))
From the measure, I create 2 card visuals to display data of Type A and Type B each. 1st visual to display type A, so I drag the measure, and also drag column Type to 'visual filter' and manually select 'A', and do the same for 2nd visual (type B).
For type A, the card display expected value (of type A and Month=2).
But for type B, the card display unexpected value (of type B and Month=1), it should be type B and Month=2 which is blank/zero. **btw, would be highly appreciated if the formula including blank value-handling to be zero (0) instead of blank.
Try
MyMeasure =
VAR MaxYear =
CALCULATE ( MAX ( DW_XYZ[Year] ), ALL ( DW_XYZ[Type] ) )
VAR MaxMonth =
CALCULATE ( MAX ( DW_XYZ[Month] ), ALL ( DW_XYZ[Type] ) )
RETURN
0
+ CALCULATE (
SUM ( DW_XYZ[Value] ),
FILTER ( DW_XYZ, DW_XYZ[Year] = MaxYear && DW_XYZ[Month] = MaxMonth )
)
A crucial difference between the above and your attempt is the inclusion of ALL applied to the Type column as a filter for CALCULATE when determining the latest year and month. Without this, the external filter you are applying to the visual will force the evaluation to consider that Type only when determining those values.

Sum of the total count (Running total based on User Count) - Is it possible?

I am trying to do the cumulative count for the users first time access the web page.
Table looks like,
UserID , Initial Access Date
100, 2019-05-10
200, 2019-05-20
100, 2019-05-21
100, 2019-05-25
200, 2019-05-30
300, 2019-06-01
Current Expression:
Cumulative Total =
CALCULATE (
DISTINCTCOUNT ( [USERID] ),
FILTER (
ALLSELECTED ( TABLE ),
[INITIAL ACCESS DATE] <= MAX ( [INITIAL ACCESS DATE] )
)
)
This only returns cumulative total count, How would I get the running total based on this count of Users.
Expected Results:
1 - Upload your Fact table in Power Bi
2 - Create a Date Table
Date = CALENDARAUTO()
Then
Year = Year('Date'[Date])
Month = MONTH('Date'[Date])
YEAR_MONTH = VALUE('Date'[Year])*100+VALUE('Date'[Month])
3 - Set relationships
4 - You can compute a set of two measures :
First
InitialAccess =
VAR InitialAccessInCurrentPeriod =
DISTINCTCOUNT(Fact_T[UserID ])
RETURN
InitialAccessInCurrentPeriod
Then :
InitialAccessCumulated =
VAR MaxDateInPeriod = MAX('Date'[Date]) // Retrieve the last date in current filter context
VAR StartingDate = MINX(ALLSELECTED('Date');[Year]) // Retrieve the lowest year selected on slicer
RETURN
CALCULATE(
[InitialAccess]; // Compute the number of initial access
FILTER( // In a nex filter context where all the dates
ALL('Date'); // Equal or superior to the lowest date selected
'Date'[Year]>=StartingDate
&&
'Date'[Date]<= MaxDateInPeriod // Until the last date visible in the current row context
)
)
You can see the final result here :
I have added to row to your fact table to have several years
Here is the Fact table used :
UserID Initial Access Date
50 12/12/2018
100 10/05/2019
200 20/05/2019
100 21/05/2019
100 25/05/2019
200 30/05/2019
300 01/06/2019
400 04/02/2020
Finally I got it working without creating extra columns or measures,
Cumulative Total =
CALCULATE (
SUMX (
Table,
IF ( DISTINCTCOUNT ( Table[UserID] ) > 0, 1, 0 )
),
FILTER (
ALLSELECTED ( Table ),
Table[InitialAccessDate]
<= MAX ( Table[InitialAccessDate] )
)
)
Cheers!!

Is there a way to create measure using variable to return last month Base size in power BI or DAX

I'm creating a report in Power BI, and want to return the last month Size.
I have a table with 4 columns named as Name, Size, Connections, Disconnections. The values on these columns are for the last 12 months. For example, Name column has A, B, C; Size column has 3608445, 2839945,874434; Connections column has 66875,85632,19237 and Disconnections column has 52658,61529 and 15832 values. These values are for the last 12 months. See screenshot below.
The code I used to created the expected table is
last_month_size =
VAR current_month =
MONTH ( TODAY () )
RETURN
CALCULATE (
[Size],
FILTER (
'Monthly Calendar_Lookup',
MONTH ( 'Monthly Calendar_Lookup'[Dates] ) = current_month - 1
)
)
I want to create a measure that will return last month Size column but the Connections and Disconnections remains the same. For example, the Size value changes while the connections and disconnections values remains the last 12 month values.
I find it difficult because the columns are on the same table.
I have researched about the question I have posted and I have found a solution.
This solution to the problem is creating measures and not using variables.
First, I created a measure called Total Size
Total Size = Sum ( Tablename [Size] )
Then, created another measure called prev_month size using DATEADD function with number_of_intervals as 0
prev_month size = CALCULATE ( [Total Size], DATEADD ('Monthly Calendar_Lookup'[Dates], 0, MONTH ) )
Next, I created measures of total connections and total disconnections
Total Connections = Sum ( Tablename [Connections] )
Total Disconnections = Sum ( Tablename [Disconnections] )
Also, I created two measures of rolling 12 months Connections and Disconnections each.
Rolling_Connections_12_months =
CALCULATE ( SUMX ('Tablename', [Total Connections] ),
DATESINPERIOD ('Date'[Month], LASTDATE ( 'Date'[Month] ), -12, MONTH ) )
Rolling_Disconnections_12_months =
CALCULATE ( SUMX ('Tablename', [Total Disconnections] ),
DATESINPERIOD ('Date'[Month], LASTDATE ( 'Date'[Month] ), -12, MONTH ) )
Drag the Name, prev_month size, Rolling_Connections_12_months, and Rolling_Disconnections_12_months on the canvas as a table visualization.
Then finally, I drag a relative Date slicer and set it as Last 1 Month.
This produces the expected results

Custom aggregate column in power bi matrix

I'm trying to create a matrix in a Power BI report summarizing Salesperson performance sliced in a number of different ways.
I know how to create a matrix with Rows - Salesperson, Columns - Product Type, and Values - count of Sales which will show the number of Sales per Salesperson per Product Type, but I'd like also be able to do the following:
Add an additional column set to pivot on (e.g. Sales Year), so that I could see count of Sales pivoted by both Product Type and Year in the same table side by side (i.e., not nested).
Add additional summary columns to my matrix showing values such as average Sale Amount by Salesperson, % of total number of Sales by Salesperson.
For clarity, I'd imagine that this would result in a matrix where the column headers read: Salesperson, Product 1, Product 2, ..., Year 1, Year 2, ..., Total Sales Count, Average Sales Amount, % of Total Sales Count. See image link below (I don't have the reputation points to include the actual image yet)
I recognize that I can do this by creating measures which effectively replicate how the matrix is splitting out the values and adding each measure as a value (no Columns), but I don't want to have to create new measures and update the matrix every year or every time we add a new Product Type.
I've also looked at custom visuals on the Power BI marketplace, but didn't see any that would achieve this.
It's possible to do this, but not super easy. You'll need a measure with a SWITCH as well as a table for your headers.
You can create a header table along these lines:
Header =
UNION (
SUMMARIZE ( Sales, Sales[Product], "Group", "By Product", "Index", 1 ),
SUMMARIZE ( Sales, Sales[Year], "Group", "By Year", "Index", 2 ),
DATATABLE (
"Header", STRING,
"Group", STRING,
"Index", INTEGER,
{
{ " Total", "Summarizations", 3 },
{ "% of Total Sales", "Summarizations", 3 },
{ "Avg Sale Size", "Summarizations", 3 }
}
)
)
Which will look like this:
Header, Group, Index,
Product 1, By Product, 1,
Product 2, By Product, 1,
2016, By Year, 2,
2017, By Year, 2,
2018, By Year, 2,
Total, Summarizations, 3,
% of Total Sales, Summarizations, 3,
Avg Sale Size, Summarizations, 3
This table will automatically expand when more products or years are added.
(Note: The Index column is so I can order them properly using Sort by Column.)
Once you have that, you just need to put Group and Header on the columns of a matrix visual and Salesperson on the rows, with a switching measure in the values.
Measure =
VAR Val =
SWITCH (
SELECTEDVALUE ( Header[Group] ),
"By Product", CALCULATE (
SUM ( Sales[Amount] ),
FILTER ( Sales, Sales[Product] = MAX ( Header[Header] ) )
),
"By Year", CALCULATE (
SUM ( Sales[Amount] ),
FILTER ( Sales, Sales[Year] = VALUE ( MAX ( Header[Header] ) ) )
),
SWITCH (
SELECTEDVALUE ( Header[Header] ),
"% of Total Sales", DIVIDE (
SUM ( Sales[Amount] ),
CALCULATE ( SUM ( Sales[Amount] ), ALL ( Sales ) )
),
"Avg Sale Size", AVERAGE ( Sales[Amount] ),
SUM ( Sales[Amount] )
)
)
RETURN
IF (
SELECTEDVALUE ( Header[Header] ) = "% of Total Sales",
FORMAT ( Val, "0.0%" ),
FORMAT ( Val, "0.0" )
)
Each different group gets its own calculation and we have to use the FORMAT function to force the table to format the percentage function properly.
(Note: If you have slicers or filtering, you probably want to use ALLSELECTED where I used ALL above.)
Here's what my table looks like (not the exact same data but similar structure)
and here's the PBIX file I created for this:
https://drive.google.com/file/d/1qxc5p53MgmOm-NH3EcivkZLhLeEHpr4R/