Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
gelsonwj
Helper I
Helper I

store only the first value of a filter and fill the rest with 0

gelsonwj_1-1672062916855.png

 

I would like to create a new column that stores only the first average value of a date and fills the rest with 0. How do I do this?

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @gelsonwj 

 

You need to add an index column to the power query first.

vzhangti_0-1672118135982.png

Column:

 

Average = 
Var _Aver=CALCULATE(AVERAGE('Table'[Quantity]),ALLEXCEPT('Table','Table'[Date_short]))
Var _minindex=CALCULATE(MIN('Table'[Index]),ALLEXCEPT('Table','Table'[Date_short]))
Return
IF([Index]=_minindex,_Aver,0)

 

vzhangti_1-1672118360990.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-zhangti
Community Support
Community Support

Hi, @gelsonwj 

 

You need to add an index column to the power query first.

vzhangti_0-1672118135982.png

Column:

 

Average = 
Var _Aver=CALCULATE(AVERAGE('Table'[Quantity]),ALLEXCEPT('Table','Table'[Date_short]))
Var _minindex=CALCULATE(MIN('Table'[Index]),ALLEXCEPT('Table','Table'[Date_short]))
Return
IF([Index]=_minindex,_Aver,0)

 

vzhangti_1-1672118360990.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

tamerj1
Super User
Super User

Hi @gelsonwj 

please try

First Average =
VAR CurrentID = 'Table'[id]
VAR DateFarmIDTable =
    CALCULATETABLE (
        'Table',
        ALLEXCEPT ( 'Table', 'Table'[Farm_id], 'Table'[Date_short] )
    )
VAR FirstRecord =
    TOPN ( 1, DateFarmIDTable, 'Table'[id] )
VAR MaxID =
    MAXX ( FirstRecord, 'Table'[id] )
VAR FirstAverage =
    MAXX ( FirstRecord, 'Table'[Average] )
RETURN
    IF ( 'Table'[id] = MaxID, FirstAverage, 0 )
FreemanZ
Super User
Super User

hi @gelsonwj 

 

try to add a column with this:

 

Average2 = 
VAR _average = [Average]
VAR _MaxID = 
MAXX(
    FILTER(TableName, TableName[Average] = _average ),
    TableName[id]
)
RETURN
IF( [id] = _MaxID, _average, 0)

 

Helpful resources

Announcements
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.