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
lokosrio
Helper II
Helper II

Filter items which are not max id

hi,

 

to get sum of distribution divided by countrows groupped by region_id of latest visit I have a calculation like this:

 

 

var _sum =
SUMX(VALUES( fact_table[region_id] ), LASTNONBLANKVALUE(fact_table[visit_id],
        SUM(fact_table[distribution_flag])))
var _count =
SUMX(VALUES( fact_table[region_id] ), LASTNONBLANKVALUE(fact_table[visit_id],
        COUNTROWS(fact_table)))
return
_sum / _count

 

 

right now on the table visualization the result looks like this:

product_idlast_visit_idperioddistribution
prod_1lv_12021P580%
prod_2lv_12021P560%
prod_3lv_32021P1140%
prod_4lv_32021P1120%
prod_5lv_32021P1190%

 

What I want to achieve is to filter those products, which are not max of last_visit_id, for example:

1. If I choose period 2021P1 to period 2021P5 then I will see:

product_idlast_visit_idperioddistribution
prod_1lv_12021P580%
prod_2lv_12021P560%

2. If I choose period 2021P1 to period 2021P11 then I will see:

prod_3lv_32021P1140%
prod_4lv_32021P1120%
prod_5lv_32021P1190%

 

Could you please help me with this?

4 REPLIES 4
v-xiaotang
Community Support
Community Support

Hi @lokosrio 

Not sure how the results come, could you post some sample data & the expected result? Thanks 🙂

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

lokosrio
Helper II
Helper II

@Greg_Deckler thank you for the answer, I get the point and modified a little the formula to get what I want:

 

 

Distribution Max Measure= 
var _sum =
SUMX(VALUES( fact_table[region_id] ), LASTNONBLANKVALUE(fact_table[visit_id],
        SUM(fact_table[distribution_flag])))
var _count =
SUMX(VALUES( fact_table[region_id] ), LASTNONBLANKVALUE(fact_table[visit_id],
        COUNTROWS(fact_table)))
VAR __Table = ALLSELECTED('fact_table')
VAR __Max = CALCULATE (
        MAX ( 'fact_table'[visit_id] ),
        FILTER (
            ALLSELECTED ( 'fact_table' ),
            'fact_table'[region_id] = SELECTEDVALUE ( 'fact_table'[region_id] )
        )
    )
VAR __Current = MAX('fact_table'[visit_id])

RETURN
   IF(__Current = __Max, var _sum / _count, BLANK())

 

 

 but for some reason this measure is not aggregating properly:

It works fine when visit_id field is added to the table, but the point is not to show visit_id and period.

Now when I choose for example periods 2021P1 to 2021P11:

product_idlast_visit_idperioddistribution
prod_1lv_12021P5 
prod_2lv_12021P5 
prod_3lv_32021P11100%
prod_3lv_42021P110%

Right now for prod_3 it shows 0%, but the visit_id and period will not be shown in the table, so the result should be:

product_iddistribution
prod_1 
prod_2 
prod_350%

Could you please help me with this?

@lokosrio Could you post some sample raw data as text? Where does the 50% come from in you last example?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Community Champion
Community Champion

@lokosrio This is sort of like a complex selector based on a lookup min/max measure like:

Distribution Max Period Measure = 
    VAR __Table = ALLSELECTED('Table')
    VAR __Max = MAXX(__Table,[period])
    VAR __Current = MAX('Table'[period])
RETURN
    IF(__Current = __Max,[distribution],BLANK())

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.