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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
game1
Helper III
Helper III

Build a graph with specific conditions

Suppose I have the table below.
I want a graph where on the Y axis, we have the number of Num and on the X axis, the dates in days and months (Table[date]). The graph will count the number of Num (Table[Num]) where the color is different from "black".

Also, there are the following conditions:
1-months and days must only be those of the last 7 days from Today()
2-Also, if a date OF THE LAST 7 DAYS does not exist in the table[date], this date should be displayed, but with the number of Num must be 0. (for example, because 2024-02-18 do not appear in the table[date], but it is part of the last 7 days from today, it must be displayed, and in the Axis Y, the value must be 0.
3-If on a specific date, we just have a color "black", the number of Num must also be 0.

So, for the last 7 days, I want the intervall of 2024-02-13 to 2024-02-19.

Capture d’écran, le 2024-02-20 à 01.22.02.png

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @game1 ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a date table.

DateTable = CALENDAR(DATE(2024,1,1),DATE(2024,12,31))

vtangjiemsft_0-1708494488129.png

(3) We can create measures. 

Measure = 
var _a= COUNTROWS(FILTER(ALL('Table'),'Table'[Date]=MAX('Table'[Date]) && 'Table'[Color] <> "black"))
RETURN IF(_a=BLANK(),0,_a)
Flag = IF(MAX('DateTable'[Date])<=TODAY() && MAX('DateTable'[Date]) >=TODAY()-6,1,0) 

(4) Place [Flag=1] on the visual object screening and then the result is as follows.

vtangjiemsft_1-1708494843694.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @game1 ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create a date table.

DateTable = CALENDAR(DATE(2024,1,1),DATE(2024,12,31))

vtangjiemsft_0-1708494488129.png

(3) We can create measures. 

Measure = 
var _a= COUNTROWS(FILTER(ALL('Table'),'Table'[Date]=MAX('Table'[Date]) && 'Table'[Color] <> "black"))
RETURN IF(_a=BLANK(),0,_a)
Flag = IF(MAX('DateTable'[Date])<=TODAY() && MAX('DateTable'[Date]) >=TODAY()-6,1,0) 

(4) Place [Flag=1] on the visual object screening and then the result is as follows.

vtangjiemsft_1-1708494843694.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

123abc
Community Champion
Community Champion

  1. Create a new calculated table or measure that generates the date range for the last 7 days from today.
  2. Use DAX to calculate the count of Num where the color is different from "black" for each date in the last 7 days.
  3. Handle cases where a date does not exist in the table[date] and where the color is "black".

Here's how you can achieve this:

  1. Calculate the Date Range for the Last 7 Days:

Last7Days =
VAR TodayDate = TODAY()
RETURN
FILTER(
CALENDAR(TODAY() - 6, TODAY()),
[Date] <= TodayDate
)

 

Calculate the Count of Num for Each Date:

 

NumCount =
VAR Last7Days = CALCULATETABLE(Last7Days, ALL(Table))
RETURN
ADDCOLUMNS(
Last7Days,
"NumCount",
CALCULATE(
COUNTROWS(Table),
Table[color] <> "black",
Table[date] = [Date]
)
)

 

 

Handle Cases Where a Date Does Not Exist or Color is "black":

 

NumCount =
VAR Last7Days = CALCULATETABLE(Last7Days, ALL(Table))
RETURN
ADDCOLUMNS(
Last7Days,
"NumCount",
IF(
ISBLANK(
LOOKUPVALUE(
Table[Num],
Table[date], [Date]
)
),
0,
IF(
LOOKUPVALUE(
Table[color],
Table[date], [Date]
) = "black",
0,
CALCULATE(
COUNTROWS(Table),
Table[color] <> "black",
Table[date] = [Date]
)
)
)
)

 

Once you have these measures or calculated tables, you can use them to create a line or bar graph where the X-axis is the date and the Y-axis is the NumCount. Make sure to use the NumCount measure as the values for your graph.

 

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

 

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

Hello, 

I have try it, but it is not working verry well. 

Capture d’écran, le 2024-02-20 à 01.22.02.pngCapture d’écran, le 2024-02-20 à 07.41.30.pngCapture d’écran, le 2024-02-20 à 07.40.50.png

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.