Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hello,
I apologize in advance, if my question doesn't make sense. It's a bit difficult to describe.
I have been trying to create a function in Power Bi, which numbers solutions based on if it is the lowest energy cost based on the investment amount. The lowest energy cost (Y axis) with the given investment (X-axis) is plotted with a line.
I have created it on excel which I use as data source, by sorting the table based on energy cost and referring to the previous investment cells to check if it is the lowest. But I can't find a way to create a similar funcition in Power Bi.
So if anyone can find a way to check, if the investment is the smallest value from previous rows with the current energy cost in Power Bi and number the results would be a great help!
Thanks for reading 🙂
Solved! Go to Solution.
@FIJT Well, if that's what you are saying to be true, then we'll go with that, here is the measure using Energy as the sorting mechanism. Just remember, sort order is not guaranteed for just about any DAX except CONCATENATEX of all things. So, just because something appears sorted in the table doesn't mean it will come back that way when you run it through a DAX formula. But if Energy is always increasing, you can do this:
Column =
VAR __Energy = [Energy cost]
VAR __CurrentInvestment = [Investment]
VAR __MinPrevInvestment = MINX(FILTER('Table',[Energy cost]<__Energy),[Investment])
RETURN
MIN(__CurrentInvestment, __MinPrevInvestment)
I think the EARLIER function is the key.
The best I've tried, is after sorting the table by energy
=IF( Table[Investment]<MINX(FILTER(Table,EARLIER(Table[Investment])),Table[Investment]),[Energy],BLANK())
@FIJT I was thinking:
Column =
VAR __OrderNumber = [Order number.]
VAR __CurrentInvestment = [Investment]
VAR __MinPrevInvestment = MINX(FILTER('Table',[Order number.]<__OrderNumber),[Investment])
RETURN
MIN(__CurrentInvestment, __MinPrevInvestment)
The only columns that we have to work with in Power Bi are Investment and Energy.
The column I am trying to create, checks if the current row of Investment is smaller than the previous rows. In excel the column (Smallest) also returns the energy value if the investment was smallest.
@FIJT Then what exactly defines "previous"? I recommend an Index column in PQ.
As the values are sorted in descending order (largest to smallest) in Power Bi, aren't the values that are higher (larger) considered previous from lower (smaller) values?
This seems like a easy function, that is somehow impossibly difficult in Power Bi.
@FIJT Well, if that's what you are saying to be true, then we'll go with that, here is the measure using Energy as the sorting mechanism. Just remember, sort order is not guaranteed for just about any DAX except CONCATENATEX of all things. So, just because something appears sorted in the table doesn't mean it will come back that way when you run it through a DAX formula. But if Energy is always increasing, you can do this:
Column =
VAR __Energy = [Energy cost]
VAR __CurrentInvestment = [Investment]
VAR __MinPrevInvestment = MINX(FILTER('Table',[Energy cost]<__Energy),[Investment])
RETURN
MIN(__CurrentInvestment, __MinPrevInvestment)
@Greg_Deckler This is the solution! Thank you 🙂
I used the formula to create (with energy sorted ascending):
@FIJT No, not a column, you would need a measure like:
= VAR __Energy = MAX([Energy Cost])
VAR __CurrentInvestment = MAX([Investment])
VAR __MinPrevInvestment = MINX(FILTER('Table',[Energy]<__Energy),[Investment])
RETURN
IF(__CurrentInvestment<__MinPrevInvestment, [Energy Cost], BLANK())
If you put Investment and Energy in a table visual along with this measure it should provide you the same information the column does and be dynamic.
Thank you so much for all the replies!
I used this to create multiple measures (don't know if it was necessary) ->
Measure 1 = MAX(Table[Investment])
Measure 2 = MAX(Table[Energy Cost])
Measure 3 =MINX(FILTER(allselected('Table'),[Energy Cost]<[Measure 2])),[Investment])
Measure 4= IF([Measure 1]<[Measure 3],[Measure 2],IF([Measure 3]<1,[Measure 2],BLANK()))
Measure 4 gives me the correct value and reacts to filters applied on the page. (Had to add the last IF, because it would skip the 1st value for some reason)
@FIJT See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column =
VAR __Current = [Value]
VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])
VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
__Current - __Previous
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
100 | |
74 | |
73 | |
49 |
User | Count |
---|---|
145 | |
109 | |
109 | |
90 | |
64 |