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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
gregoliveira
Helper II
Helper II

Week and Month Sales considering a choosen day

Hey, friends!

 

I need to create a report to present sales on a specific day. More than this, I must present sales that week and that month. The day will be selected in a slicer.  The report works; however, I failed to understand why my first shot failed to show the correct value. I believe I misunderstood something about context evaluation. If someone can help to identify where I am failing, I will be very grateful.

 

To accomplish my goal, I created a calculated table with the names of these days and created a relationship between my calendar table and my sales table. (Calculated table * <--> 1 Calendar table 1 <--> * Sales table)

 

gregoliveira_0-1691932979491.png

 

I author the following measure to scan the filter context in the slicer and compute the weekly sales. However, instead of presenting the whole week, it shows only the chosen day.

 

Faturamento 2. Semana =

VAR diaEscolhido =

    MIN( D_CALENDARIO_PERIODOS[Data] )

VAR semanaEscolhida =

    CALCULATE( MIN ( D_CALENDARIO[Semana Ano] ), D_CALENDARIO[Date] = diaEscolhido )

VAR anoEscolhido =

    CALCULATE( MIN ( D_CALENDARIO[Ano Número] ), D_CALENDARIO[Date] = diaEscolhido )

VAR tabelaSemana =

    CALCULATETABLE (

        ALL ( D_CALENDARIO ),

        D_CALENDARIO[Semana Ano] = semanaEscolhida

            && D_CALENDARIO[Ano Número] = anoEscolhido

    )

RETURN

    CALCULATE( [Vendas Valor] , tabelaSemana )

 

I tried to replace the tabelaSemana for other table functions, for example, FILTER, but the result is the same. The only way that this structure works fine is by removing the relationship and using them apart. This is a picture with the relationship activated:

 

gregoliveira_1-1691933029798.png

PS.: the measure is used in the second gauge.

 

The code to generate my calculated table is:


D_CALENDARIO_PERIODOS =

SELECTCOLUMNS (

    UNION (

        ADDCOLUMNS ( { TODAY () }, "Período", "Today", "Ordem", 1 ),

        ADDCOLUMNS ( { TODAY () - 7 }, "Período", "Last week", "Ordem", 2 ),

        ADDCOLUMNS (

            { DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, DAY ( TODAY () ) ) },

            "Período", "Last month",

            "Ordem", 3

        ),

        ADDCOLUMNS (

            { DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 2, DAY ( TODAY () ) ) },

            "Período", "Last bimester",

            "Ordem", 4

        ),

        ADDCOLUMNS (

            { DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 3, DAY ( TODAY () ) ) },

            "Período", "Last 3 month",

            "Ordem", 5

        ),

        ADDCOLUMNS (

            { DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 6, DAY ( TODAY () ) ) },

            "Período", "Last semester",

            "Ordem", 6

        ),

        ADDCOLUMNS (

            { DATE ( YEAR ( TODAY () ) - 1, MONTH ( TODAY () ), DAY ( TODAY () ) ) },

            "Período", "Last  year",

            "Ordem", 7

        ),

        ADDCOLUMNS (

            DATESBETWEEN(

                D_CALENDARIO[Date],

                MIN ( D_CALENDARIO[Date] ),

                TODAY()

            ),

            "Período", "Choose",

            "Ordem", 8

        )

    ),

    "Data", [Value],

    "Período", [Período],

    "Ordem", [Ordem]

)

 

Thanks a lot!

 

1 ACCEPTED SOLUTION
gregoliveira
Helper II
Helper II

Hey, friends!

I understand what is happening. I used the performance analyzer feature to retrieve the DAX query and got that the slicers were reinforcing the filter context propagated by the D_CALENDARIO_PERIODOS table. I can fix the measure by add a remove filter modifier, but I believe that the best choice is remove the relationship between the tables.

Well, this is it!

See you!

View solution in original post

1 REPLY 1
gregoliveira
Helper II
Helper II

Hey, friends!

I understand what is happening. I used the performance analyzer feature to retrieve the DAX query and got that the slicers were reinforcing the filter context propagated by the D_CALENDARIO_PERIODOS table. I can fix the measure by add a remove filter modifier, but I believe that the best choice is remove the relationship between the tables.

Well, this is it!

See you!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.