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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
kamalmalek20
Regular Visitor

Counts in Specific conditions

dear All, i need Dax Formula to add new column in table with following condition

number of days in same month included item in store, example : item 1111 in Store A repeated in 1-2-3 Oct so repeated days is 3, "Note i need in same month " so if you have data in 

Date Store item Repeated days in this month

Date            str     item     Days repeated per month

10/1/2024    A    1111      3
10/1/2024    B    1111      1
10/1/2024   C     2222     1
10/1/2024   D    3333      2
10/1/2024   A    1111      3
10/2/2024   A    1111      3
10/3/2024   A    1111      3
10/3/2024   A    1111      3
10/3/2024   D    3333     2

7 REPLIES 7
kamalmalek20
Regular Visitor

Dear Supporters , Can you please support this issue , i am seeking your proposed solution  

v-xinruzhu-msft
Community Support
Community Support

Hi,

Thanks for the solution @Greg_Deckler  offered, and i want to offer some more information for user to refer to.

hello @kamalmalek20 , you can create the following calculated column.

Column =
CALCULATE (
    DISTINCTCOUNT ( 'Table'[Date] ),
    FILTER (
        'Table',
        'Table'[str] = EARLIER ( 'Table'[str] )
            && [item] = EARLIER ( 'Table'[item] )
            && EOMONTH ( [Date], 0 ) = EOMONTH ( EARLIER ( 'Table'[Date] ), 0 )
    )
)

Output

vxinruzhumsft_0-1730341685786.png

Best Regards!

Yolo Zhu

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

 

 

thanks a lot , but this formula taking much time of loading then taking much time to refresh data 

kamalmalek20_0-1730361656605.png

 

Hi @kamalmalek20 

Please try this

 

Column =
VAR a = 'Table'[str]
VAR b = 'Table'[item]
VAR c = [Date]
VAR _table =
    FILTER (
        'Table',
        'Table'[str] = a
            && [item] = b
            && EOMONTH ( [Date], 0 ) = EOMONTH ( c, 0 )
    )
RETURN
    CALCULATE ( DISTINCTCOUNT ( 'Table'[Date] ), _table )

 

Best Regards!

Yolo Zhu

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

 

thanks for supporting , 30 min and still runing 😞

kamalmalek20_0-1730366100587.png

 

Greg_Deckler
Super User
Super User

@kamalmalek20 Try:

Column = 
    VAR __Item = [Item]
    VAR __MonthYear = YEAR( 'Table'[Date] ) * 100 + MONTH( 'Table'[Date] )
    VAR __Table = ADDCOLUMNS( 'Table', "__MonthYear", YEAR( [Date] ) * 100 + MONTH( [Date] ) )
    VAR __Table1 = SUMMARIZE( FILTER( __Table, [__MonthYear] = [__MonthYear] && [Item] = __Item ), [Item], [Date] )
    VAR __Result = COUNTROWS( __Table1 )
RETURN
    __Result


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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

dear , its not working then you didnt mention store becuase it is related to date and store and item

kamalmalek20_0-1730296295638.png

 

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

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

Top Kudoed Authors