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
jcamilo1985
Helper III
Helper III

max in pre-aggregate table

good evening experts

again I have a difficulty that I hope you can help me solve, I need to make a measurement, basically it is to assign a custom format, the idea is to obtain the maximum of [amount] for each day, however as seen in the table for every day it throws the same value, and I don't know what I'm doing wrong.

- the fact table is related to a calendar table by date
- the measure [amount] is simply a countrows of the fact table

any help will be welcome. Thank you

dia maximo.png

 

1 ACCEPTED SOLUTION
jcamilo1985
Helper III
Helper III

Goodnight

It's been a while since I've been back here, the truth is that with so much work sometimes time becomes too limited, however I didn't want to let this post go by without including the solution so that if someone else is in the same predicament they can find it here a guide and a solution.
Basically the syntax that works is:

 

=
CALCULATETABLE (
ADDCOLUMNS ( ALL ( Calendario[Nombre del día] ), "@hurtos", [cantidad] ),
REMOVEFILTERS ( Calendario[Número del día] )
)

this excellent video explains what is happening, it really is something that is not at all intuitive 

Finally, the measure was needed to place a conditional format, therefore the final one is as follows:

color bars =
VAR table =
CALCULATETABLE (
ADDCOLUMNS ( ALL ( Calendar[Day name] ), "@thefts", [amount] ),
REMOVEFILTERS ( Calendar[Day of week] )
)
maximum VAR =
MAXX ( table, [@thefts] )
VARE color =
SWITCH ( TRUE (), [amount] >= maximum, "#8C0000", "#BDBEBF" )
RETURN
color
hope this helps in some way

 

View solution in original post

10 REPLIES 10
jcamilo1985
Helper III
Helper III

Goodnight

It's been a while since I've been back here, the truth is that with so much work sometimes time becomes too limited, however I didn't want to let this post go by without including the solution so that if someone else is in the same predicament they can find it here a guide and a solution.
Basically the syntax that works is:

 

=
CALCULATETABLE (
ADDCOLUMNS ( ALL ( Calendario[Nombre del día] ), "@hurtos", [cantidad] ),
REMOVEFILTERS ( Calendario[Número del día] )
)

this excellent video explains what is happening, it really is something that is not at all intuitive 

Finally, the measure was needed to place a conditional format, therefore the final one is as follows:

color bars =
VAR table =
CALCULATETABLE (
ADDCOLUMNS ( ALL ( Calendar[Day name] ), "@thefts", [amount] ),
REMOVEFILTERS ( Calendar[Day of week] )
)
maximum VAR =
MAXX ( table, [@thefts] )
VARE color =
SWITCH ( TRUE (), [amount] >= maximum, "#8C0000", "#BDBEBF" )
RETURN
color
hope this helps in some way

 

tamerj1
Super User
Super User

Hi @jcamilo1985 
I have just simulated your measure using a similar dataset and seems to works just fine. See screencshot below.

1.png

What results are you getting? Not sure if you have other slicers or filters that are affecting the result.

tamerj1
Super User
Super User

Hi @jcamilo1985 

What kind of relationship is there beween the two tables? You are slicing by day name from the calendar table, right?  Would you please try retun COUNTROWS ( resumen ) and see what results you get. My understanding that you want the max value fro each day name among all weeks so I believe ADDCOLUMNS should be iterating over VALUES ( Year- Week )

This is how the relationship between calendar and facts is constructed.

relacionamiento.png

 In effect what I am looking for is that for each day of the week the value is 75653 for this case

@jcamilo1985 

What is the code of [Amount]?

ryan_mayu
Super User
Super User

@jcamilo1985 

could you pls provide the sample data and expected output?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Good afternoon

First of all thank you for coming to my aid.

 

resultado.pngthe result would basically be the highest number of events per day for each day of the week

 

Hi  @jcamilo1985 ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can update the formula of measure [color dias] as below:

color dias = 
VAR _tab =
    ADDCOLUMNS (
        ALL ( 'Calendar' ),
        "@maxqty",
            SUMX (
                FILTER (
                    ALLSELECTED ( 'dataset de prueba' ),
                    WEEKNUM ( 'dataset de prueba'[fecha_hecho], 2 )
                        = SELECTEDVALUE ( 'Calendar'[Week] )
                        && FORMAT ( 'dataset de prueba'[fecha_hecho], "dddd" )
                            = EARLIER ( 'Calendar'[Nombre del dia] )
                ),
                [cantidad]
            )
    )
RETURN
    MAXX ( _tab, [@maxqty] )

yingyinr_0-1656469820178.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. 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.

@jcamilo1985 

maybe you can try this

Measure 2 = maxx(ALL('Table'[ID]),[Measure])

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




first of all thank you very much for coming to my aid, I had previously tried this measure, but I don't know why it is failing in grain of the day, note that it works at the ID level

nuevo resultado.png

 

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.