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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
kgr
Frequent Visitor

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

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 @kgr 

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.

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

Mariusz
Community Champion
Community Champion

Hi @kgr 

 

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

 

kgr
Frequent Visitor

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

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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