Forum Discussion

Mike91's avatar
Mike91
Icon for Helper I rankHelper I
1 year ago
Solved

distinctcount item filtered by value

Hi All, i need your help to resolve this problem. 

01/02/2024Item A50
05/02/2024Item B30
10/02/2024Item A50
15/02/2024Item B20
22/02/2024Item C30

 

how i can count the number of item sales under 100?

my goal is Item < 100 = 2 and item > 100 = 1

i tried with summarize function and count.

thanks for the help

  • Anonymous's avatar
    Anonymous
    1 year ago

    Thank you bhanu_gautam, I have the following thoughts:

    Hi, Mike91 

    Based on your chat with Super User, I used the example data you provided as shown in the image below:

    First, I create a calculated table using this DAX expression:

    Table 2 = 
    VAR _table = SUMMARIZE(
    	'Table',
    	'Table'[Date],
    	'Table'[Item],
    	'Table'[Value],
    	"Month", FORMAT(
    		'Table'[Date],
    		"MMMM"
    	),
    	"Year", FORMAT(
    		'Table'[Date],
    		"YYYY"
    	)
    )
    RETURN
    ADDCOLUMNS(
    	ADDCOLUMNS(
    		SUMMARIZE(
    			_table,
    			'Table'[Item],
    			[Month],
    			[Year]
    		),
    		"Res", VAR _year = [Year]
    		VAR _month = [Month]
    		VAR _item = 'Table'[Item]
    		RETURN
    			SUMX(
    				FILTER(
    					ALL('Table'),
    					FORMAT(
    						'Table'[Date],
    						"YYYY"
    					) = _year && FORMAT(
    						'Table'[Date],
    						"MMMM"
    					) = _month && 'Table'[Item] = _item
    				),
    				'Table'[Value]
    			)
    	),
    	"IsAbove100", IF(
    		[Res] > 100,
    		1,
    		0
    	)
    )

    This will calculate the total values for each item for each month and determine if the total values for that month are greater than 100.

    I then created two measures using the following two expressions:

    Above100 = COUNTAX(FILTER(SUMMARIZE('Table 2','Table 2'[IsAbove100],'Table 2'[Item]),'Table 2'[IsAbove100]=1),'Table 2'[Item])
    Below100 = COUNTAX(FILTER(SUMMARIZE('Table 2','Table 2'[IsAbove100],'Table 2'[Item]),'Table 2'[IsAbove100]=0),'Table 2'[Item])

    At this point, we use the columns and months of the calculated table to create a table visual, a slicer, and a card, respectively:

    When I select any month in the slicer, it calculates whether the total value of the corresponding item is greater than 100 items.

    I've provided the Pbix file below.

     

     

    Best Regards

    Jianpeng Li

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

9 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thank you bhanu_gautam, I have the following thoughts:

    Hi, Mike91 

    Based on your chat with Super User, I used the example data you provided as shown in the image below:

    First, I create a calculated table using this DAX expression:

    Table 2 = 
    VAR _table = SUMMARIZE(
    	'Table',
    	'Table'[Date],
    	'Table'[Item],
    	'Table'[Value],
    	"Month", FORMAT(
    		'Table'[Date],
    		"MMMM"
    	),
    	"Year", FORMAT(
    		'Table'[Date],
    		"YYYY"
    	)
    )
    RETURN
    ADDCOLUMNS(
    	ADDCOLUMNS(
    		SUMMARIZE(
    			_table,
    			'Table'[Item],
    			[Month],
    			[Year]
    		),
    		"Res", VAR _year = [Year]
    		VAR _month = [Month]
    		VAR _item = 'Table'[Item]
    		RETURN
    			SUMX(
    				FILTER(
    					ALL('Table'),
    					FORMAT(
    						'Table'[Date],
    						"YYYY"
    					) = _year && FORMAT(
    						'Table'[Date],
    						"MMMM"
    					) = _month && 'Table'[Item] = _item
    				),
    				'Table'[Value]
    			)
    	),
    	"IsAbove100", IF(
    		[Res] > 100,
    		1,
    		0
    	)
    )

    This will calculate the total values for each item for each month and determine if the total values for that month are greater than 100.

    I then created two measures using the following two expressions:

    Above100 = COUNTAX(FILTER(SUMMARIZE('Table 2','Table 2'[IsAbove100],'Table 2'[Item]),'Table 2'[IsAbove100]=1),'Table 2'[Item])
    Below100 = COUNTAX(FILTER(SUMMARIZE('Table 2','Table 2'[IsAbove100],'Table 2'[Item]),'Table 2'[IsAbove100]=0),'Table 2'[Item])

    At this point, we use the columns and months of the calculated table to create a table visual, a slicer, and a card, respectively:

    When I select any month in the slicer, it calculates whether the total value of the corresponding item is greater than 100 items.

    I've provided the Pbix file below.

     

     

    Best Regards

    Jianpeng Li

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

  • Mike91 , Create a measure to calculate the total sales for each item:

    TotalSales = SUM('Table'[Sales])
    Then create a measure to count the number of items with total sales under 100:
    DAX
    ItemsUnder100 =
    CALCULATE(
    COUNTROWS('Table'),
    FILTER(
    'Table',
    [TotalSales] < 100
    )
    )
     
    • Mike91's avatar
      Mike91
      Icon for Helper I rankHelper I

      i tried, but not working count a number of transaction for each item. for example in my dataset in april i sold 328 item, i calculate in excell 100 of them sold <100, with you formula i count the single transaction under 100 for each item. 

       

      • bhanu_gautam's avatar
        bhanu_gautam
        Icon for Super User rankSuper User

        Mike91 , It is not clear can you explain in detail with example what exactly are you looking for