Self-reference a column in DAX or Power Query - powerbi

I am looking to create column D of the table below in power query or DAX. You can see the excel formula in the cell. I need to add columns from the current row and add a previously calculated row above. The column is self-referencing. I am stuck and do not know how to proceed. Any help would be appreciated.

You cannot recursively self-reference a column in DAX. See here for more detail on that.
That said, just like the examples linked in that post (also below), you don't really need recursion for your purpose but rather a cumulative total of Production - Demand plus an initial inventory amount.
That is, something like this:
Projected Inv. =
CALCULATE (
SUM ( Table1[Production] ) - SUM ( Table1[Demand] ),
FILTER ( Table1[Date], Table1[Date] <= MAX ( Table1[Date] ) )
) + 174408
How to perform sum of previous cells of same column in PowerBI
DAX - formula referencing itself

Related

Calculated column Running MAX of values so far in DAX

Can you help me with how can I have a column in DAX to store the running MAX of values so far.
My table has two columns named as DateTimeStamp column and Value column and I want to have a new column that shows me the MAX value so far in another column.
Your kind guidance is highly appreciated.
See
Lots of articles and videos on this. http://sqlbi.com is probably the most useful, comprehensive, and authoratitive site for help with DAX.
Read https://www.sqlbi.com/articles/computing-running-totals-in-dax/
So
Running MAX of value =
var MaxTimestamp = max( 'Table'[DateTimeStamp] )
return calculate(
max( 'Table'[Value] ),
'Table'[DateTimeStamp] <= MaxTimestamp,
ALL ( 'Table'[DateTimeStamp] )
)

DAX PowerBI: Calculating sum of column based on other column

I am trying to calculate the TotalFTE, but I can't figure it out. I am fairly new to DAX and trying to make the best of it with some studycases.
The table contains a lot of columns, but these are the columns that are needed for the measure.
The measure should sum the highest FTE in a year per ID and ignore the blanks in ID.
I've build a measure that gives an error when I try to visulise the result in a card. My measure: TotalFTE = CALCULATE(MAX(Table[FTE]), FILTER(Table, DISTINCT(Table[ID])))
Any feedback?
Moving forward, please post data as tables in stack and refrain from provide the data as image.
Measure =
SUMX (
GROUPBY (
'Fact',
'Fact'[year],
'Fact'[ID],
"#Max", MAXX ( CURRENTGROUP (), 'Fact'[FTE] )
),
[#Max]
)

COUNTIF in Power BI (New calculated column Required)

I want to calculate the running count of each value based on column A. In Excel, I am applying the following formula
=COUNTIF($A$2:$A2,A2)
I would like to get the same result in Power BI. Can you please advise.
With just a single column, this is impossible in DAX because duplicated rows cannot be distinguished as there is no inherent order to a column.
However, if you have an index column on the table (you can easily add one in the Query Editor), then it is possible to define such a calculated column so that it works similarly to the Excel formula.
CountIf =
VAR CurrentIndex = DATA[Index]
RETURN
CALCULATE (
COUNTROWS ( DATA ),
ALLEXCEPT ( DATA, DATA[ITEM] ),
DATA[Index] <= CurrentIndex
)

How to calculate dynamic Required Measure using TotalMeasure in DAX in which i need to exclude the BLANK() & 0 in NetRevenue for those SKU's?

I want to calculate the RequiredMeasure column in DAX as shown in the below figure.
If I remove the Product SKU then the value should not change it should show the total values of RequiredMeasure as 200 only as shown in the below figure.
Please find the below screenshot for clear understanding.
SUMX is the function you need, to iterate over all rows of the table, and calculate an expression:
Required Measure =
SUMX (
Table1,
Table1[Net Revenue] * Table1[Total Measure]
)
Worked example file: https://pwrbi.com/so_55255241/

DAX Measure to determine % of parent row in column chart

I've been struggling to find a way to achieve the result of a matrix visualization in Power BI, in a line and clustered column chart.
I have tried using ALLSELECTED, ALL, ALLEXCEPT in order to ignore one filter but no matter how I try it, I'm not reaching my end goal.
CarCountPerCategory =
CALCULATE(
DISTINCTCOUNT(Table[CarID]),
ALLSELECTED(Table[Filter])
)
This still breaks down the measure to the Filter level instead of ignoring it. I am looking for something that will give me the total distinct count regardless of the Filter column. E.g. TimesReshopped 1 - 190 on all 3 columns, TimesReshopped 2 - 182 on all 3 columns of the Filter Column series. I need this as a sidestep in order to divide the distinct car count to the total distinct car count per times reshopped in order to reach the percentage that I am looking for. (the one in the matrix)
Can someone help me with some advice? Thank you.
Try this:
[Total Category Count]:=
SUMX ( SUMMARIZE ( Table, Table[TimesReshopped] ), [Count of CarID] )
I got to the bottom of this by using ALLEXCEPT and providing all the filter that I was using:
CarCountPerCategory =
CALCULATE(
DISTINCTCOUNT(Table[CarID]),
ALLEXCEPT(Table,Table[Year],Table[Month],Table[LocationName],Table[CustCode],Table[TimeReshoped])
)