I was attempting to employ the formulas here to calculate a running total of a column in PowerBI. However, my data is time-independent. In addition, every other running total calculation I've seen for PowerBI has been in reference to a date field. The target column is a "Frequency" column, and represents the estimated frequency of the event represented by each record. How do I generate a cumulative total of these frequencies, from lowest frequency to greatest? This is used to generate an exceedence curve for the consequences of events based on the running frequency total, called an F-N curve.
Per this site: https://www.daxpatterns.com/cumulative-total/, I was able to generate the following measure:
Measure_cumF =
CALCULATE (
sum([content.F]),
FILTER (
ALLSELECTED( Sheet1),
Sheet1[Content.N] >= MIN ( Sheet1[Content.N] )
)
)
"MIN" allows the cumulative sum of "Content.F" to start at the row containing the highest value of the desired sorting list, in this case "Content.N". "MAX" will start the cumulative sum at the row containing the lowest value of "Content.N".
"ALLSELECTED" applies the current filters to the measure. Replace with "ALL" to have a static value that always returns the cumulative sum of the entire column.
Related
I have a "Line and clustered column chart" in Power BI where the bars are actual values and line is budgeted values. Actual and budgeted values often vary enough that their Y axis scaling doesn't match, so I need both axes to have the same scale. Start value for both could be zero, but End needs to be calculated. We need to dynamically calculate End based on the visible data within the chart. My approach so far has been to create a measure that calculates the highest monthly actual value and another measure that calculates the highest monthly budget value, then take that max of those two measures and use it in a function for the "End" value of both Y axes. I have not found the DAX that works yet.
Example of y axes with different scaling and the max value we want
I suspect I'll need to get the min and max dates that are selected in the visual, and the following measures give me those:
MinSelectedDate = CALCULATE(MIN('Date'[CalendarDate]), ALLSELECTED('Date'))
MaxSelectedDate = CALCULATE(MAX('Date'[CalendarDate]), ALLSELECTED('Date'))
I also suspect I'll need to build a table within the measure and summarize the values then iterate over that table to find the max. Somthing like this:
MaxActual = MAXX(
SUMMARIZE(ALLSELECTED('FactActualValues'), 'Date'[FirstDayOfMonth], "Volume", [Actual Values]),
[Actual Volumes]
)
However, when I try this DAX the data ends up being sliced by the month within each year. I'm using a matrix for dev/test.
Dev/test using matrix
The optimal solution is to have an analytical model with two columns (Date and FY).
Cancel dynamization of the table, setting the years to the "Year" column and converting it to Text type
Create the column "Month" from the month number of "MonthName" and convert to type Text
Create the date column of the format dd-mm-yyyyy from the concatenation using "01/"+[Month]+"/"+[Year]
Format the new date column to date format
The y-axis scale is resolved by the "Clustered Column Chart" visualization as it takes the maximum value of a single column of values plus some margin at the top and takes that as the y-axis value.
Got it! I was very close but didn't need to calculate min or max dates. Using ALLSELECTED gave me just the records from the FactActualValues table that I needed without applying an explicit filter. I also learned that some functions (e.g. - MAX) cannot "see" columns returned by table functions, but others like MAXX do support it. SUMMARIZE allows you to create a column and I learned that some people use the empty single quote to reference such a column.
Here's the DAX that works:
MaxMonthlyActual =
MAXX(
SUMMARIZE(
ALLSELECTED('FactActualValues'),
'Date'[FirstDayOfMonth],
"#ActVol", SUM('FactActualValues'[Total])
),
''[#ActVol]
)
Here is what the chart looks like using the DAX measure:
Chart with Y axes with matching scales
I want to create two measures that sum up the values of column 2 when column 2 equals column 1's parameters.
For example I have a column named Current/Reset and another column named Linear Ft. I want to sum up the values of Linear Ft where column 1 = "Current" and then again for "Reset."
I continue to get errors when I try and write the formula. Any help is much appreciated!
First of all you don't need explicit measures for this. It's the default behaviour of Power BI to sum up numbers (aka. implicit measure), and if you filter Linear Ft. by the (unique) values of Current/Reset you get your desired result.
However, if you still want to have separate measures for this, use CALCULATE()
Current Sum =
CALCULATE(
SUM('Table'[Linear Ft.]),
'Table'[Current/Reset] = "Current"
)
Reset Sum =
CALCULATE(
SUM('Table'[Linear Ft.]),
'Table'[Current/Reset] = "Reset"
)
This is the Sample Data what i want to do is for each document (field "REQUIREMENT_DESCRIPTION") calculate time difference by subtracting the time in "ACTION_DATE" n row from n+1 row.
And then calculate the mean and standard deviation of each document validation time.
So after searching online i found this formula which calculates the difference in time row by row.
First i split the column ACTION_DATE by "space" delimeter to separate time from date and than named the time field "ACTION_TIME".
Diff in Seconds = DATEDIFF(
Table[ACTION_TIME],
CALCULATE(
MIN([ACTION_TIME]),
FILTER(ALL(Table), Table[ACTION_TIME] > EARLIER(Table[ACTION_TIME]))
),
SECOND
)
I've started to manage PowerBi from a couple of weeks so i'm a little bit confused about some things.
My problem is that i need a Matrix in my dashboard with percent values but i want the total in number value because the total of a percent of row shows me always 100% and i dont know about the number i'm working
This is my Matrix with percentage values
This is how i want the total of row returns me but with the columns values ins percentage
I've tried to make a measure counting the values
COUNT(OPSRespuestas[answer])
After that turn off the total of rows and add this measure to the values in my matrix but this is what i get
This is my table after trying add a measure with the total
It returns me the total for each of the columns and not the total of all my rows.
These are the tables i'm working with
This my top header values
This is my left header values
The answer column is what i need to count
This is my relationship between this 3 tables although i have many more intermediate table aside from this 3 as you're going to see in the next picture:
My relationship tables
So finally what i need is that this matrix shows me the total of answer in percentage for each of departments and group of questions and then show me total by department but with number value
The problem you are experiencing has to do with context. Each row is seen as it own total population hence the 100% total. Each column in this row is evaluated against the total of that row to provide a percentage value.
In addition to adding a custom measure to replace the total, you could also consider computing a percentage against the grand total of all dimensions. This means that each cell gets evaluated against the the total of all rows and columns. In this ways the cell value would change compared to your first table but the row total does not evaluate to 100% anymore.
SUM ( [Value] ) / CALCULATE ( SUM ( [Value] ) ; ALL ( 'Your Table' ) )
I am trying to aggregate the following values (NHS, Social Care and Both B) by the reasons for delays column so i can find the reason with the highest value (from the 3 combined values named above).
I have tried using summarize to create a table with just the reasons for delays ,NHS, Social Care and Both B columns. By doing this i hoped i could create a column named totals which adds the NHS, Social Care and Both B Columns together in this summarized table thus giving me the total values for each reason for delay.
Though when i tried to run a maxx function around my totals column it seems to give me the wrong values.
I have tried wrapping my table with the distinct function so it aggregates all the columns in my summarize together, but this did not help either.
Max Delays =
MAXX (
SUMMARIZE (
csv,
csv[Reason For Delay],
csv[NHS],
csv[Social Care],
csv[Both B],
"totals", CALCULATE ( SUM ( csv[NHS] ) + SUM ( csv[Both B] ) + SUM ( csv[Social Care] ) )
),
[totals]
)
The smaller table (which should represent the summarized table) in the above picture with the total column shows the values i expect to carry my max calculation over, where i expect the max value to be 277.
The max value i am getting instead is 182. This is the max value in the unsummarized table below where i have multiple duplicates of my reasons for delay column and 182 is the highest value.
I have uploaded a sample of the pbix file i am working on if it may be of help;https://www.zeta-uploader.com/en/1184250523
First, create a measure for total reasons:
Total Reasons = SUM(csv[NHS]) + SUM(csv[Both B]) + SUM(csv[Social Care])
Second, create a measure for the max reason:
Max Reason = MAXX( VALUES(csv[Reason For Delay]), [Total Reasons])
Result:
How it works:
The first measure is for convenience. You can re-use it in other formulas, making code cleaner;
In the second measure, we create a list of distinct reasons using VALUES. Then MAXX iterates this list, calculates total for each reason, and then finds the largest of them.