Dynamic max value in GENERATESERIES - powerbi

I have a slicer which is based on a calculated table:
Prediction Measures = GENERATESERIES(0, 10000, 100)
I want to set the max value dynamically depending on other applied filters on the report page, so I figured I could use a measure as the max value in the GENERATESERIES but this does not work.

Related

calculated column stops working when exdternal filter used

I have some Fact Revenue, I am trying to group by Conca, and display the values only if negative…
For doing it I have this calculated column:
=
VAR name1 = Revenue[Conca]
VAR name2=
CALCULATE (
SUM ( Revenue[CostOfQuality] ),
FILTER ( Revenue, Revenue[Conca] = name1 )
)
RETURN
if (name2>0, 0, Revenue[CostOfQuality])
It works:
(highest value is 0 as expected):
Now...
If I drag fiscal year it stops working:
Why is it that I see numbers higher than 0?? (I want it to still work even if I bring other filters...)
a calculated column is computed computed once on the whole dataset after the data are loaded, and is basically a "static column".
Whatever the expected result, you are looking for a measure, which gets computed in the current context
Calculated columns and calculated tables are different from measures, since they are static: You can filter them, but they don't recalculate on filter changes.

Calculate date diff between column date for each row and min slicer date

I think that the following formula summarize pretty well what I want to achieve:
date diff =
ABS (
DATEDIFF (
data_table[login_date],
SELECTEDVALUE ( 'Date'[Date] ),
DAY
)
)
but it returns me the following error
A single value for column 'login_date' in table 'data_table' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.
In other word I want have a column in my data_table with date diff calculated dynamically based on min slicer date selection.
My final goal is to filter out dynamically users that has not been logged for the last 3 months based on the slicer date range.
Here is the dataset
user_id, login_date
111, 01/02/2021
222, 02/15/2021
444, 03/15/2021
555, 01/15/2021
I want user ID to be filtered out when the number of days between the max date of the date range and the day of the last connection is higher than 90 days.
Edit
I'm adding a different formula I'm working on but having few issues to make it work
active users = CALCULATE( DISTINCTCOUNT(data_table[id]), ( FILTER ( VALUES ( data_table[id] ), DATEDIFF(IF( ISBLANK(SELECTEDVALUE(data_table[login_date])),[Min range date],SELECTEDVALUE(data_table[login_date])),[Max range date],DAY) < 90 ) ))
You can't have a dynamically calculated column, but you can use a measure to do this. The issue that you have with your calculation is that it needed to do a row by row evaluation, rather than over a column. That is why you get an 'A single value for column 'login_date' in table 'data_table' cannot be determined' error.
In this case you can use SUMX, as this is a iterator and it will do row by row. So using the following measures:
Selected Date = SELECTEDVALUE('Calendar'[Date])
This reads the date selected. You can wrap it with a MIN/MAX if needed depending on how your slicer is set up. You can change the slicer to single select, it you just want one value.
Date Calc = SUMX('Table', DATEDIFF('Table'[Login_date], [Selected Date], DAY))
This uses SUMX to calculate on a row by row level.
You can then use this measure to drive your visual. In this example I've filtered out those over 30 days since the login
If you choose a new date, it will recalculate straight away. This should set you on the right path for your use case.

Power BI : Filters in What-If parameter

I have a table with multiple company data and having company_id column in it. I want to show the slider with maximum value of selected company_id for ranking feature to the report.
I have created a measure to calculate count for the maximum value of selected company.
Max Value = CALCULATE(DISTINCTCOUNT(SOURCE_TABLE[Company_Name]),FILTER(SOURCE_TABLE,SOURCE_TABLE[Company_id]=SELECTEDVALUE(SOURCE_TABLE[Company_id])))
But when I try to use this for What-if parameter in ranking feature getting below error,
TopRank = GENERATESERIES(1,[Max Value], 1)
Error Code:
The arguments in GenerateSeries function cannot be blank.
When I use DISTINCTCOUNT function it works fine, but with filter it had an issue.
TopRank = GENERATESERIES(1,DISTINCTCOUNT(SOURCE_TABLE[Company_Name]),
1)
-- This is working fine
How can I get the value of DISTINCTCOUNT with FILTER. Any ideas will be appreciated.!
As you may have noticed, What-If parameter table is a calculated table.
Calculated table is re-calculated only when you have refreshed the data source. It will not be re-calculated based on user interaction, such as selecting a company ID in the slicer.
In your scenario, you need to create the parameter table with a possible maximum number. And, you may filter the slicer so that it only shows the available numbers only based on the currently selected company ID.
You can do that by creating a measure which indicates whether the parameter is available for the currently selected company ID. For example,
__AvailableRankFlag = IF( [TopRank Value] <= [Max Value], 1 )
and add this measure to filter of the slicer with "__AvailableRankFlag is 1".

If a exists pick a else pick b power bi

I have forecast and budget values for the year, and a new forecast is created every quarter. I need PowerBI to pick up the Metric Value (can be Budget, Q1F, Q2F and Q3F) for a given date based on data availability.
Example - If for a given date, data for Q3F is available, pick Q3F, else pick Q2F else Q1F else budget.
This is what my data looks like:
Date Metric Value
1/1/11 Budget 1.1
1/1/11 Q3F 1.2
1/1/11 Q2F 1.3
In this case the function should pick up Q3F since it's available.
One way to solve this would be by using both a SUMX and a SWITCH Statements.
To start with assign a constant to your forecasts, e.g. budget = 1, Q1F = 2 and so on as a column on your data. The idea more recent forecast will have a higher number, it will be used in the switch statement late. I am going to refer to it as forecast_ID in this example.
I am also assuming you have a calendar table, also that your forecasts are entered in entirely for the business and not in waves. E.g. Category A is still on budget, Category B is an updated forecast.
The idea of below, is that the SUMX iterates though each quarter that you are looking at, e.g. 2018 would run Q1, Q2, Q3, Q4 separately.
Within the context of each quarter, it is getting the MAX of your forecast IDs, which is then used in the switch to select the most recent forecast.
Measure :=
SUMX (
VALUES ( Calendar[Quarter] ),
SWITCH (
MAX ( table1[forecast_ID] ),
1, CALCULATE ( SUM ( table1[value] ), table1[Metric] = "Budget" ),
2, CALCULATE ( SUM ( table1[value] ), table1[Metric] = "Q1F" )
)
)
You could also then do something like MAX ( table1[forecast_ID] - 1) for finding the previous forecast dynamically.
If you always want to pull the most recent value then you can use LASTNONBLANK
As Marcus mentioned, the first step is to create a constant for your forecasts. I set up a separate table for this example.
Then you can create a relationship between the two tables based on Metric. Add a calculated column to your original table
MetricConstant = RELATED(Table2[Constant])
Now create a measure to pull the most recent value within each date period
Measure =
SUMX (
VALUES ( Table1[Date] ),
CALCULATE ( SUM ( Table1[Value] ), LASTNONBLANK ( Table1[MetricConstant], 1 ) )
)
Now when you pull in the Date and the Measure it will only show you the most recent available
EDIT-Updated based on comments. If you want to view which Metric is being used you need another measure
MetricMeasure = CALCULATE(MAX(Table1[Metric]),LASTNONBLANK(Table1[MetricConstant],1))
You could create an area chart based on that, and add this to the tooltip.

Find Max for each day in PowerBI and DAX

I am trying to find the maximum route for each day based on the count of cars in PowerBI/DAX.
An example of my data is as follows:
Date Route Count
01-Nov-17 A 10
01-Nov-17 B 5
02-Nov-17 A 2
02-Nov-17 C 22
03-Nov-17 B 2
Hence I want to find the max count of route for each date and display the results of a table like so...
Date Route Count
01-Nov-17 A 10
02-Nov-17 C 22
03-Nov-17 B 2
Any suggestions would be very much appreciated.
Thanks,
Fiona
First, define measure for max car count:
[Max Count] = MAX( Cars[Count] )
If you drop this measure into a pivot against dates, it will show you max car counts per date.
Define second measure:
[Max Routes] =
VAR Period_Max_Count = [Max Count]
RETURN
CONCATENATEX (
FILTER ( Cars, [Max Count] = Period_Max_Count ),
Cars[Route], ","
)
This measure will return a string of routes per date that have max count. You need a list instead of one value because of potential ties - multiple routes might have the same max count per period. It's not in your data example, but just to demonstrate this, I added an extra record for the first date:
The way this measure works:
first, it saves max car count per date into a variable.
second, it filters car table to select only routes that have count equal to max count for the date.
third, it iterates over the filtered table and concatenates route names into a list separated by comma.
Right-click the table choose New quick measure
In Calculation drop-down select Max per category
In Base value field, drag the Count column. In this, the value will be aggregated to Sum by default so instead change it to Max of Count
In Category field, drag the route column
Voila! Magic happens! The measure that is created, when plotted against the axis Route will give Max(Count) per Route.
Here is what the DAX will look like:
Count max per route =
MAXX(
KEEPFILTERS(VALUES('Table1'[route])),
CALCULATE(MAX('Table1'[Count]))
)
(so one can directly use this DAX without wanting to drag but i dont understand the DAX at this moment tbh)
Lucky reference for me:
https://learn.microsoft.com/en-us/power-bi/desktop-quick-measures
Create a calculated column with formula:
MAX = IF(CALCULATE(
MAX(Table1[Count]);
FILTER(
Table1;
Table1[Date] = EARLIER(Table1[Date])
)
) = Table1[Count]; Table1[Route]; BLANK())
Create your table and make a page level filter to show all non-blank values of Table1[MAX].