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
matthieu_rsu
Regular Visitor

Comparing previous year and current

Hello,

 

My goal is to compare the cost of different non qualities between the past year and the current year.

 

I used the following logic :

Coste_LY = CALCULATE(
    SUM(Tabla_CNQ_NCR[Coste_CNQ_Total]),
    FILTER(
        ALL(Tabla_CNQ_NCR),Tabla_CNQ_NCR[CNQ_Año] = MAX(Tabla_CNQ_NCR[CNQ_Año])
        )
    )
 
I get the following result :
matthieu_rsu_0-1680190063470.png

I can see that I'm considering the total of the current year but I don't know how to filter it by category.

 

Thanks in advance for your help

 

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

Hi @matthieu_rsu ,

Please update the formula of measure [Coste_LY] as below and also put the field [CNQ_Año] onto your table visual.

Coste_LY =
VAR _selyear =
    SELECTEDVALUE ( Tabla_CNQ_NCR[CNQ_Año] )
VAR _seltype =
    SELECTEDVALUE ( Tabla_CNQ_NCR[TIPOF] )
VAR _preyear =
    CALCULATE (
        MAX ( Tabla_CNQ_NCR[CNQ_Año] ),
        FILTER (
            ALLSELECTED ( Tabla_CNQ_NCR ),
            Tabla_CNQ_NCR[TIPOF] = _seltype
                && Tabla_CNQ_NCR[CNQ_Año] < _selyear
        )
    )
RETURN
    CALCULATE (
        SUM ( Tabla_CNQ_NCR[Coste_CNQ_Total] ),
        FILTER (
            ALLSELECTED ( Tabla_CNQ_NCR ),
            Tabla_CNQ_NCR[TIPOF] = _seltype
                && Tabla_CNQ_NCR[CNQ_Año] = _preyear
        )
    )

vyiruanmsft_0-1680488008684.png

If the above one can't help you get the expected result, please provide some raw data in your table 'Tabla_CNQ_NCR' (exclude sensitive data) with Text format, your table visual settings and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
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
matthieu_rsu
Regular Visitor

Hello,

 

Sorry for the late reply.

Thank you very much for the answers and how to act correctly on this forum.

 

I will have a better look in a few days.

Best regards

Ashish_Mathur
Super User
Super User

Hi,

Create a Calendar Table.  Create a relationship (Many to One and Single) from the Date column of the Data Table to the Date column of the Calendar Table.  In the Calendar Table, write calculated column formulas for Year, Month name and Month number.  Sort the Month name column by the Month number.  Create a slicer of year from the Calendar Table and select a year.  Write these measures

Measure = sum(Tabla_CNQ_NCR[Coste_CNQ_Total])

Measure LY = calculate([Measure],previousyear(calendar[date]))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-yiruan-msft
Community Support
Community Support

Hi @matthieu_rsu ,

Please update the formula of measure [Coste_LY] as below and also put the field [CNQ_Año] onto your table visual.

Coste_LY =
VAR _selyear =
    SELECTEDVALUE ( Tabla_CNQ_NCR[CNQ_Año] )
VAR _seltype =
    SELECTEDVALUE ( Tabla_CNQ_NCR[TIPOF] )
VAR _preyear =
    CALCULATE (
        MAX ( Tabla_CNQ_NCR[CNQ_Año] ),
        FILTER (
            ALLSELECTED ( Tabla_CNQ_NCR ),
            Tabla_CNQ_NCR[TIPOF] = _seltype
                && Tabla_CNQ_NCR[CNQ_Año] < _selyear
        )
    )
RETURN
    CALCULATE (
        SUM ( Tabla_CNQ_NCR[Coste_CNQ_Total] ),
        FILTER (
            ALLSELECTED ( Tabla_CNQ_NCR ),
            Tabla_CNQ_NCR[TIPOF] = _seltype
                && Tabla_CNQ_NCR[CNQ_Año] = _preyear
        )
    )

vyiruanmsft_0-1680488008684.png

If the above one can't help you get the expected result, please provide some raw data in your table 'Tabla_CNQ_NCR' (exclude sensitive data) with Text format, your table visual settings and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

How to provide sample data in the Power BI Forum

How to Get Your Question Answered Quickly

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

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

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.