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
saumitra
Helper I
Helper I

Apply DAX Formula to Separate Dates

Hi All, 

I am trying to apply DAX formula to a daily report. However, when new raw data is pulled in Power BI, the DAX formula gives a combined result. But, I want a separate result for each date. 

In order to understand my problem, I am attaching a sample: 

saumitra_2-1615200920148.png

 

This is the data for 2 days. After applying the DAX formula, it is giving a combined result. But, I want it as follows for different dates: 

saumitra_1-1615200350865.png

 

I hope my question is understandable. Kindly please provide a solution as to how to apply the formula in such a way that the answers are not combined with the former date. 

 

 

Thank you,

Regards,

Saumitra Upadhyaya

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @saumitra 

You just need to add 'Table (4)'[Date] = EARLIER('Table (4)'[Date]) into your codes. Change table's name per your need. 

Countif = COUNTAX(FILTER('Table (4)','Table (4)'[Name] = EARLIER('Table (4)'[Name]) && 'Table (4)'[Company] = EARLIER('Table (4)'[Company]) && 'Table (4)'[Date] = EARLIER('Table (4)'[Date]) && 'Table (4)'[Index] <= EARLIER('Table (4)'[Index])),'Table (4)'[Company])
HC = IF('Table (4)'[Countif] <= 1, 1, 0)
SUM1 = SUMX(FILTER('Table (4)','Table (4)'[Name] = EARLIER('Table (4)'[Name]) && 'Table (4)'[Date] = EARLIER('Table (4)'[Date])),'Table (4)'[HC])
HC1 = DIVIDE('Table (4)'[HC],'Table (4)'[SUM1],0)

031005.jpg

 

Additionally, you can also try below codes to get the same result.

HC2 = DIVIDE('Table (4)'[HC],CALCULATE(SUM('Table (4)'[HC]),ALLEXCEPT('Table (4)','Table (4)'[Date],'Table (4)'[Name])),0)

 

Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.

View solution in original post

3 REPLIES 3
v-jingzhang
Community Support
Community Support

Hi @saumitra 

You just need to add 'Table (4)'[Date] = EARLIER('Table (4)'[Date]) into your codes. Change table's name per your need. 

Countif = COUNTAX(FILTER('Table (4)','Table (4)'[Name] = EARLIER('Table (4)'[Name]) && 'Table (4)'[Company] = EARLIER('Table (4)'[Company]) && 'Table (4)'[Date] = EARLIER('Table (4)'[Date]) && 'Table (4)'[Index] <= EARLIER('Table (4)'[Index])),'Table (4)'[Company])
HC = IF('Table (4)'[Countif] <= 1, 1, 0)
SUM1 = SUMX(FILTER('Table (4)','Table (4)'[Name] = EARLIER('Table (4)'[Name]) && 'Table (4)'[Date] = EARLIER('Table (4)'[Date])),'Table (4)'[HC])
HC1 = DIVIDE('Table (4)'[HC],'Table (4)'[SUM1],0)

031005.jpg

 

Additionally, you can also try below codes to get the same result.

HC2 = DIVIDE('Table (4)'[HC],CALCULATE(SUM('Table (4)'[HC]),ALLEXCEPT('Table (4)','Table (4)'[Date],'Table (4)'[Name])),0)

 

Regards,
Community Support Team _ Jing
If this post helps, please Accept it as the solution to help other members find it.

Hey @v-jingzhang , thank you very much! Both your solutions work perfectly. 

amitchandak
Super User
Super User

@saumitra , Try new columns like

 

countif= countx(filter(Table, [name] =earlier([name]) && [company] =earlier([company] && [Date] =earlier([Date])), [name])

 

HC = if([countif] <=1,1,0)

 

HC1 = divide([HC],Sumx(filter(Table, [name] =earlier([name])&& [Date] =earlier([Date])), [HC]))

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.

Top Solution Authors