cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Natantis
Frequent Visitor

sum by mainItem

Hi, 

What I thought would be an easy tasked proved more complex then I thought

 

Table A

itemSKcount
a5
b5
c6
d6
a7
b6
b1
d3

 

Item table

ItemSKMainitemid
ao
bo
cp
dp

 

Result

ItemCount by mainitem
a24
b24
c15
d15

 

 

Help me write dax for "Count by mainitem" please 🙂

 

I could give you all my filed attempts but i don't think it will help(?)

 

regards

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @Natantis 

See the attached PBIX.

 

First, you should ensure the model is set up like this (which I imagine it already is):

OwenAuger_0-1685689954823.png

 

Then create this measure:

Count by mainitem = 
CALCULATE (
    SUM ( 'Table A'[count] ),
    REMOVEFILTERS ( 'Item' ),
    VALUES ( 'Item'[Mainitemid] )
)

This measure sums 'Table A'[count] for the values of 'Item'[Mainitemid] corresponding to the visible rows of 'Item', but removing any other filters on the 'Item' table.

 

OwenAuger_1-1685690032769.png

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

3 REPLIES 3
Natantis
Frequent Visitor

Hi @OwenAuger

 

Thanks for your quick reply. 
I am getting an error on REMOVEFILTERS, 


"Cannot find name 'REMOVEFILTERS'
'REMOVEFILTERS' is not a function."

 

I am using direct query to access data and there is a connection between the tabels like you describe (My model is more complex then this but I scaled down to only highlight the importnat parts. 

I replaced REMOVEFILTER with ALL and from what i can se this is giving me the deciered result. 

Thanks

Glad to hear it's working (using ALL rather than REMOVEFILTERS).

These functions are indeed equivalent when used in this way.

 

If REMOVEFILTERS is unavailable, I'm guessing you are connecting to an older version of Analysis Services Tabular.

 

For reference, the compatibility for DAX functions can be found on dax.guide:

https://dax.guide/removefilters/

OwenAuger_0-1685695002117.png

 


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn
OwenAuger
Super User
Super User

Hi @Natantis 

See the attached PBIX.

 

First, you should ensure the model is set up like this (which I imagine it already is):

OwenAuger_0-1685689954823.png

 

Then create this measure:

Count by mainitem = 
CALCULATE (
    SUM ( 'Table A'[count] ),
    REMOVEFILTERS ( 'Item' ),
    VALUES ( 'Item'[Mainitemid] )
)

This measure sums 'Table A'[count] for the values of 'Item'[Mainitemid] corresponding to the visible rows of 'Item', but removing any other filters on the 'Item' table.

 

OwenAuger_1-1685690032769.png

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors