Power BI: Multiply by each point between two values. (Calculate Curve) - powerbi

I'm working with a dataset where I have a Min Value and a Max value and then a sales value.
If the Min value = 100, the max value = 110 and the Sales value equal to 10. Then I have to create a line chart which plots the output of each number between the min and max multiplied by the sales value.
Which looks like below
The goal is to create a line like below
Is there a way of doing this In Power BI via Dax as I am currently creating a mart table with a cursor for each record in the table containing the initial rows which is getting quite large?

You can create a (calculated) table like this:
Expanded_Data =
GENERATE(
'RawData';
SELECTCOLUMNS(
var maxMinusMin = [Max]-[Min]
return
GENERATESERIES(
[Min]*maxMinusMin;
[Max]*maxMinusMin;
maxMinusMin
);
"Plot_Point"; [Value]
)
)
Where 'RawData' is the table name which has at least two columns named [Max] and [Min] :
1
In this way you don't need the sales value info. Just substitute the variable for the sales value column

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.

How to get a max of a measure?

I have the below data:
(last column shall be a sum grouped by BU and UP).
I have achieved the last column SubTotalBU, by doing:
SubTotalBU = CALCULATE ( sum(Sheet1[NSR]), ALLSELECTED(), VALUES(Sheet1[BU]), VALUES(Sheet1[UP]) )
My goal is to get the max of column SubTotalBU for each UP… That is; I need a column with all values 90 in this case.
I have tried using MAX of SubTotalBU, but MAX doesn’t work with measures… How can I get the desired result?
To display all max total in your table report, you need to create a new column for the value, else the table will auto filter the value base on the table row:
First, create new column for Total BU:
Tottal BU = CALCULATE(SUM(Sheet1[NSR]),FILTER(Sheet1,Sheet1[Bu] = EARLIER(Sheet1[Bu])))
Next, create a new column to record only max value from the Total BU
Max BU = MAX(Sheet1[Tottal BU])
Sample data with new column:
Table Report:

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.

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].

DAX returning incorrect total in total row

I have four input columns "Location, Material, Revenue, Volume". I need to create a new column "STG_Measure" using DAX. This expression is returning wrong value for total row. "STG" column has expected output.
STG_Measure = IF(
COUNTROWS(VALUES(Sheet1))=1
,DIVIDE([YTD_Revenue],[YTD_Volume])
,SUMX(
VALUES(Sheet1[Material])
,DIVIDE([YTD_Revenue],[YTD_Volume])
)
)
I tried placing other columns in SUMX function but it didn't work. In actual data Revenue and Volume are also measures returning YTD totals.