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

power bi dax Min date of each category

Hi Community,

I am familiar with SQL and I can write a query to return results of a query to Select MIN(Date), MAX(Date), SUM(quality) and GROUP BY. However, I am new to Power BI and DAX and find it difficult to do the same on Power BI. Below is my situation.

These tables on Power BI:

Dim_ManefactureDate

 

peternznguyen_7-1656494237354.png

 

 

Dim_ReleaseDate

 

peternznguyen_8-1656494270405.png

 

Fact_OrderID

 

peternznguyen_9-1656494304580.png

 

 

Table Relationships 

 

peternznguyen_10-1656494317460.png

 

 

Adding a table visualization to a new page to show data from three tables above, data is showing as below: 

 

peternznguyen_11-1656494374112.png

 

 

Under Values of Visualizations, when selecting SUM over Netweight, it automatically summarizes expected Netweight. However, for ManufactureDate and ReleaseDate, when selecting Earliest then Power BI table shows unexpected 1/01/1900 values like this:

 

peternznguyen_12-1656494429003.png

 

I expect earliest date of each OrderID as below:

 

peternznguyen_13-1656494460348.png

 

I have also tried to use a DAX function to create a new column but it gets error

ManufactureDate_Earliest = 
    VAR Sum_Netweight = SUM(Fact_OrderID[NetWeight])
    VAR GroupBy_OrderID = GROUPBY(Fact_OrderID,Fact_OrderID[OrderID])
    RETURN
        CALCULATE(
             MIN(RELATED(Dim_ManufactureDate[DateBK]))
            )

Thank you very much for your help

Peter

2 ACCEPTED SOLUTIONS
SpartaBI
Community Champion
Community Champion

@peternznguyen there are few ways to approach it, but becasue you are very new, so let's try this. Why didn't you just put the date columns from the fact instead of the dim?

View solution in original post

@peternznguyen  the measures will look like:

Earliest_CompletionDate = 
CALCULATE(
    MIN(CompletionDate[DateBK]),
    CROSSFILTER(Fact_ShippingKPI[CompletionDate_DateSK], CompletionDate[DateSK], BOTH)
)






2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

View solution in original post

4 REPLIES 4
SpartaBI
Community Champion
Community Champion

@peternznguyen there are few ways to approach it, but becasue you are very new, so let's try this. Why didn't you just put the date columns from the fact instead of the dim?

@SpartaBI , thank you for your reply. Dim_ManufactureDate and Dim_ReleaseDate were from Dim_Date that contains many other columns such as DayOfMonthCode, DayOfWeekCode, FullDateDesicription, MonthOfYearDescription, etc., so that's why I don't put everything in the Fact table. I have tried using Matrix but I don't expect the result from Matrix.

@peternznguyen ok, will PM you now

@peternznguyen  the measures will look like:

Earliest_CompletionDate = 
CALCULATE(
    MIN(CompletionDate[DateBK]),
    CROSSFILTER(Fact_ShippingKPI[CompletionDate_DateSK], CompletionDate[DateSK], BOTH)
)






2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

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.