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
RamGSK
Frequent Visitor

Average of Previous value and next value for Nulls (Average of row after and row before in Power BI)

Hi,

 

Can someone advise how to calculate average of previous value and next value when we have a blank value in the Sales field in Power BI.

 

E.g., Scenario:

 

Date

Sales

1-Jul

10

2-Jul

 

3-Jul

30

4-Jul

 

5-Jul

50

6-Jul

 

7-Jul

70

8-Jul

 

9-Jul

90

10-Jul

 

 

 

Expected Output:

Date

Sales

Expected Sales

1-Jul

10

10

2-Jul

 

20

3-Jul

30

30

4-Jul

 

40

5-Jul

50

50

6-Jul

 

60

7-Jul

70

70

8-Jul

 

80

9-Jul

90

90

 

 

 

 

Thanks,

1 ACCEPTED SOLUTION
mickey64
Super User
Super User

Step 0: I use these data.

mickey64_0-1721577640032.png

 

Step 1: I add a 'Index' column on Power Query Editor.

- Before -

mickey64_1-1721577717472.png

- After -

mickey64_2-1721577785075.png

 

Step 2: I add 3 colmuns to the 'DATA' colum on Power BI Desktop.

    PrevDay Sales = LOOKUPVALUE(DATA[Sales],DATA[Index],'DATA'[Index]-1) 

    NextDay Sales = LOOKUPVALUE(DATA[Sales],DATA[Index],'DATA'[Index]+1)

    Expected Sale = IF('DATA'[Sales]>0,
                                'DATA'[Sales],
                                ('DATA'[PrevDay Sales]+'DATA'[NextDay Sales])/2
                              )

mickey64_3-1721578070015.png

 

View solution in original post

2 REPLIES 2
RamGSK
Frequent Visitor

Can this be achieved without Index as it is showing incorrect values when slicer is applied for e.g., on Date, etc.

mickey64
Super User
Super User

Step 0: I use these data.

mickey64_0-1721577640032.png

 

Step 1: I add a 'Index' column on Power Query Editor.

- Before -

mickey64_1-1721577717472.png

- After -

mickey64_2-1721577785075.png

 

Step 2: I add 3 colmuns to the 'DATA' colum on Power BI Desktop.

    PrevDay Sales = LOOKUPVALUE(DATA[Sales],DATA[Index],'DATA'[Index]-1) 

    NextDay Sales = LOOKUPVALUE(DATA[Sales],DATA[Index],'DATA'[Index]+1)

    Expected Sale = IF('DATA'[Sales]>0,
                                'DATA'[Sales],
                                ('DATA'[PrevDay Sales]+'DATA'[NextDay Sales])/2
                              )

mickey64_3-1721578070015.png

 

Helpful resources

Announcements
Europe Fabric Conference

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.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

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

August Carousel

Fabric Community Update - August 2024

Find out what's new and trending in the Fabric Community.