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
Anonymous
Not applicable

Difference of two columns (distinction stored in rows)

Hello, 

 

I have a report showing articles and a inventory value per month. The month information is stored in one column and contains e.g. 01-2019, 02-2019. 

 

Article 1  /  01-2019: 100   02-2019: 200

 

I would like to calculate Table[inventory value] as difference for the last period and the previous one = 200-100 = +100.

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi

Create a date table and create a relationship between this date table and your table.

CALENDAR =
ADDCOLUMNS (
    CALENDARAUTO (),
    "MM-YY", FORMAT ( [Date], "mm-yyyy" ),
    "year", YEAR ( [Date] ),
    "month", MONTH ( [Date] )
)

Create measures in your table, 

Measure =
VAR noblank =
    CALCULATE (
        SUM ( 'Table'[value] ),
        FILTER ( 'CALENDAR', 'CALENDAR'[Date] <> BLANK () )
    )
RETURN
    IF (
        SUM ( 'Table'[value] ) = BLANK (),
        CALCULATE ( 0, FILTER ( 'CALENDAR', 'CALENDAR'[Date] = BLANK () ) ),
        noblank
    )

Measure 3 = [Measure]-[Measure 2]

Add [article] and [Measure 3] in a table or matrix, you will get the result as expected.

Capture4.JPG

Best Regards

Maggie

View solution in original post

6 REPLIES 6
v-juanli-msft
Community Support
Community Support

Hi

Create a date table and create a relationship between this date table and your table.

CALENDAR =
ADDCOLUMNS (
    CALENDARAUTO (),
    "MM-YY", FORMAT ( [Date], "mm-yyyy" ),
    "year", YEAR ( [Date] ),
    "month", MONTH ( [Date] )
)

Create measures in your table, 

Measure =
VAR noblank =
    CALCULATE (
        SUM ( 'Table'[value] ),
        FILTER ( 'CALENDAR', 'CALENDAR'[Date] <> BLANK () )
    )
RETURN
    IF (
        SUM ( 'Table'[value] ) = BLANK (),
        CALCULATE ( 0, FILTER ( 'CALENDAR', 'CALENDAR'[Date] = BLANK () ) ),
        noblank
    )

Measure 3 = [Measure]-[Measure 2]

Add [article] and [Measure 3] in a table or matrix, you will get the result as expected.

Capture4.JPG

Best Regards

Maggie

Anonymous
Not applicable

Hi Maggie, 

 

thank you for your help. I got the first part working. 

 

In the measure I get the following error, which I am clueless how to resolve: "The syntax for 'FILTER' is incorrect."

I replace TABLE with my tables name.

 

Thanks again for your help.

Hi @Anonymous 

Make sure you create a measure, also you create relationships for the calendar table and your data table.

If you are unable to slove this, please share the screenshot which can make me clear more about this.

 

 

Best Regards
Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Here comes the screenshot. Thanks again for your help.2019-08-07_11-42-33.jpg

Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

Can You provide a data sample?

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
Mariusz Repczynski

 

Anonymous
Not applicable

2019-08-01_17-18-34.jpg

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Kudoed Authors