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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Antara
Helper I
Helper I

Running Division on First Date

Hello Experts,
I was trying to create measure in DAX on the following data: 
Table Name: Sample

Product_id         date                  My_price         sales          other_price     Indexed other price
12345               20200701          100                75               120                 
12345               20200704          100                22               130                 
12345               20200705          100               56                140                 
12345               20200706          100               52                140                 
12345               20200731          100               99                140                
12345               20200801          100              24                 150                
12345               20200809          100              58                 120                
12345              20200907           100              24                 200                
12345              20200908           100             39                 120                 
12345              20200908           100             56                 100                 
12345              20200908           100             64                 125                 

Formula for Indexed other price=other_price/first_other_price_in_the_month * 100

Below is expected output:
Product_id         date                  My_price         sales          other_price     Indexed other price
12345               20200701          100                75               120                 100
12345               20200704          100                22               130                 108.3333333
12345               20200705          100               56                140                 116.6666667
12345               20200706          100               52                140                 116.6666667
12345               20200731          100               99                140                 116.6666667
12345               20200801          100              24                 150                100
12345               20200809          100              58                 120                 80
12345              20200907           100              24                 200                100
12345              20200908           100             39                 120                   60
12345              20200908           100             56                 100                  50
12345              20200908           100             64                 125                 62.5


In above example For:
July Month first_other_price_in_the_month=120 (to be used in formula for july month data)
August Month first_other_price_in_the_month=150 (to be used in formula for Augmonth data)
September Month first_other_price_in_the_month=200 (to be used in formula for Sept month data)

Note: I have 100 different Product_ID, in above example have considered only one product_id.
Any help or suggestion on DAX code for populating indexed other price would be highly appreciated.
Thanks

2 ACCEPTED SOLUTIONS
UAV-Test-Pilot
Helper II
Helper II

@Antara  you can see @edhans answer for this same question here: https://community.powerbi.com/t5/Desktop/Runnig-Division/m-p/1268413

 

If this helped, I would appreciate a Kudos!
If this resolves the issue, please mark it as a Solution! 🙂

View solution in original post

Hi @Antara ,

 

Please try like this:

 

Create a month column:

Month = MONTH('Table'[date])

Create measures:

Measure = 
VAR first_date =
    MINX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[date] <= MIN ( 'Table'[date] )
                && 'Table'[Month] = MAX ( 'Table'[Month] )
        ),
        'Table'[date]
    )
VAR first_other_price =
    CALCULATE (
        SUM ( 'Table'[other_price] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Product_id], 'Table'[Month] ),
            'Table'[date] = first_date
        )
    )
RETURN
    DIVIDE ( SUM ( 'Table'[other_price] ) * 100, first_other_price )

 

AVG = 
AVERAGEX(ALLEXCEPT('Table','Table'[date]),[Measure])

 

v-xuding-msft_0-1596532003878.png

v-xuding-msft_1-1596532086030.png

 

Best Regards,
Xue Ding
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

5 REPLIES 5
UAV-Test-Pilot
Helper II
Helper II

@Antara  you can see @edhans answer for this same question here: https://community.powerbi.com/t5/Desktop/Runnig-Division/m-p/1268413

 

If this helped, I would appreciate a Kudos!
If this resolves the issue, please mark it as a Solution! 🙂

Thanks @UAV-Test-Pilot   for the quick response. I really appreciate. If in case I want perform average on top of measure across date (irrespective of Product_id). Can we create average measure on top of this measure?

 

In short,

 

To show date, avg_of_Measure_created_below in a table visual. If we have date as 20200701 for 2 Product_ID(say 12345 and 56789) and Measure(created using formula mention by @edhans ) as value 100 and 200 then table visual should show:

 

Output:

date           avg_measure

20200701  150

 

Any help or suggestion would be helpful

 

Thanks

Hi @Antara ,

 

Please try like this:

 

Create a month column:

Month = MONTH('Table'[date])

Create measures:

Measure = 
VAR first_date =
    MINX (
        FILTER (
            ALL ( 'Table' ),
            'Table'[date] <= MIN ( 'Table'[date] )
                && 'Table'[Month] = MAX ( 'Table'[Month] )
        ),
        'Table'[date]
    )
VAR first_other_price =
    CALCULATE (
        SUM ( 'Table'[other_price] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Product_id], 'Table'[Month] ),
            'Table'[date] = first_date
        )
    )
RETURN
    DIVIDE ( SUM ( 'Table'[other_price] ) * 100, first_other_price )

 

AVG = 
AVERAGEX(ALLEXCEPT('Table','Table'[date]),[Measure])

 

v-xuding-msft_0-1596532003878.png

v-xuding-msft_1-1596532086030.png

 

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

Hi @v-xuding-msft 

Can we multiply it by sales before taking average, For example:

PRODUCT_ID    date                     sale   other_price

10                       01-07-2020        100      10

10                       02-07-2020        200       20

20                       01-07-2020        300       30

20                      02-07-2020        400        40

Befor  sum of other price  can we multiply by sales like      AVERAGE(10*100,30*300)/Sum(100+300)    for  date 01/07/2020

Thanks


Hi @Antara ,

 

Please try this:

 

sales * other_price = SUM('Table 1'[sales])* SUM('Table 1'[other_price])


AVG = 
var avg_ = AVERAGEX(ALLEXCEPT('Table 1','Table 1'[date]),[sales * other_price])
var totalsales = CALCULATE(SUM('Table 1'[sales]),ALLEXCEPT('Table 1','Table 1'[date]))
return
DIVIDE(avg_,totalsales)

v-xuding-msft_0-1596597103454.png

 

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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.