Repository: usd-cs/COMP-49X-24-25-TransactCampus
Pull request #17: Dax scripts for updating the home page that displays the total orders…
Author: login: estebanrodriguez28
Created: 2025-03-06T07:15:00Z | Merged: 2025-03-06T08:11:53Z

… and allowing user to compare to previous weeks also for calculating data for the dinner report like number of unique students ordering dinner

# Overview

**Type of Change:** _TODO:_ Pick one of the following: New Feature.

**Summary:** _TODO: Dinner report needed to be updated with the correct data so created dax scripts to calculate and use correct data. Also needed to update home, breakfast, and lunch with the ability to compare orders to previous dates weeks ago like I did for dinner.

## UI/UX Implementation
<img width="1349" alt="Screenshot 2025-03-05 at 11 10 44 PM" src="https://github.com/user-attachments/assets/67e44be9-b203-4bb3-b07d-6cc49f27a049" />
<img width="1326" alt="Screenshot 2025-03-05 at 11 10 52 PM" src="https://github.com/user-attachments/assets/ba0a2815-3264-48d3-8eff-b4144a1e84a9" />

<img width="1338" alt="Screenshot 2025-03-05 at 11 11 02 PM" src="https://github.com/user-attachments/assets/c16f50d5-08f1-4150-8415-2d9a6248dc9e" />
<img width="1392" alt="Screenshot 2025-03-05 at 11 11 10 PM" src="https://github.com/user-attachments/assets/643c5a53-9b6b-43b9-8604-48a892778e17" />

_TODO: The home (total), breakfast, and lunch reports were updated to include the ability to select a date and week from dropdown menus to compare that date either yesterday up to 4 weeks ago. Also updated dinner report to include correct data.

## Model Updates

N/A

### Data Models

_TODO: "No changes made."_

### Object-Oriented Models

_TODO: "No changes made."_

## End-to-End Testing Instructions

_TODO: Open project in vscode, run python3 app.py, sign in to power bi. Then navigate to one of the pages (home, breakfast, lunch) and select a date and week from dropdown menu. The data should match dummy data.



Diff:
diff --git a/DAX/calculating_dinner_data.txt b/DAX/calculating_dinner_data.txt
new file mode 100644
index 0000000..93d9971
--- /dev/null
+++ b/DAX/calculating_dinner_data.txt
@@ -0,0 +1,31 @@
+MonthlyDinnerOrders = 
+SUMMARIZE (
+    FILTER (
+        'public orders',
+        HOUR('public orders'[local_time]) >= 16 && 
+        HOUR('public orders'[local_time]) < 22
+    ),
+    ('public orders'[local_time]),
+    "Total Orders", COUNT('public orders'[orderid])
+)
+
+TotalItemsDinnerPeriod = 
+CALCULATE (
+    SUM('public transactions'[number_of_items]),
+    FILTER (
+        'public transactions',
+        HOUR('public transactions'[released_datetime]) >= 16 &&
+        HOUR('public transactions'[released_datetime]) < 22
+    )
+)
+
+
+UniqueUsersDinnerPeriod2 = 
+CALCULATE (
+    DISTINCTCOUNT('public transactions'[userid]),
+    FILTER (
+        'public transactions',
+        HOUR('public transactions'[released_datetime]) >= 16 &&
+        HOUR('public transactions'[released_datetime]) < 22
+    )
+)
\ No newline at end of file
diff --git a/DAX/total_compare_selected_week.txt b/DAX/total_compare_selected_week.txt
new file mode 100644
index 0000000..a94ae4b
--- /dev/null
+++ b/DAX/total_compare_selected_week.txt
@@ -0,0 +1,49 @@
+Dropdown menus
+
+TotalWeekSelection = 
+DATATABLE(
+    "Week Name", STRING, 
+    "Week Offset", INTEGER,
+    {
+        {"Yesterday", -1},
+        {"Last Week", -7},
+        {"Two Weeks Ago", -14},
+        {"Three Weeks Ago", -21},
+        {"Four Weeks Ago", -28}
+    }
+)
+
+
+TotalDateSelection = 
+ADDCOLUMNS(
+    CALENDAR(DATE(2025,1,1), DATE(2025, 5, 31)),  
+    "Formatted Date", FORMAT([Date], "MM/DD/YYYY")
+)
+
+
+Selected Date Orders Total = 
+VAR SelectedTimeBucket = MAX(Total_Orders_Hourly_Buckets[Hour])
+VAR SelectedStart = SELECTEDVALUE(TotalDateSelection[Date]) + SelectedTimeBucket
+VAR SelectedEnd = SelectedStart + TIME(1,0,0)
+
+RETURN 
+CALCULATE(
+    COUNT('public orders'[orderid]),
+    'public orders'[local_time] >= SelectedStart,
+    'public orders'[local_time] < SelectedEnd
+)
+
+
+
+
+Selected Week Orders Total = 
+VAR SelectedTimeBucket = MAX(Total_Orders_Hourly_Buckets[Hour])
+VAR WeekStart = (SELECTEDVALUE(TotalDateSelection[Date]) + SELECTEDVALUE(TotalWeekSelection[Week Offset])) + SelectedTimeBucket
+VAR WeekEnd = WeekStart + TIME(1,0,0)
+
+RETURN 
+CALCULATE(
+    COUNT('public orders'[orderid]),
+    'public orders'[local_time] >= WeekStart,
+    'public orders'[local_time] < WeekEnd
+)
\ No newline at end of file


Reviews:
user: login: SDjon
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-06T07:54:49Z
user: login: SDjon
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-06T07:56:59Z
user: login: SDjon
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-06T08:02:52Z
user: login: SDjon
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-06T08:08:12Z
user: login: SDjon
body: Some extra lines to prepare for future problems would be good to add but in general this works and is still mostly readable. The scripts follow good spacing and indentation. 
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-03-06T08:10:59Z

Review comments:
diff_hunk: @@ -0,0 +1,31 @@
+MonthlyDinnerOrders = 
+SUMMARIZE (
+    FILTER (
+        'public orders',
+        HOUR('public orders'[local_time]) >= 16 && 
+        HOUR('public orders'[local_time]) < 22
+    ),
+    ('public orders'[local_time]),
+    "Total Orders", COUNT('public orders'[orderid])
+)
+
+TotalItemsDinnerPeriod = 
+CALCULATE (
+    SUM('public transactions'[number_of_items]),
+    FILTER (
+        'public transactions',
+        HOUR('public transactions'[released_datetime]) >= 16 &&
+        HOUR('public transactions'[released_datetime]) < 22
+    )
+)
+
+
+UniqueUsersDinnerPeriod2 = 
path: DAX/calculating_dinner_data.txt
user: login: SDjon
body: UniqueUsersDinnerPeriod2 has a 2 while others do not. If there is no first one, then the number 2 is not necessary and is a naming inconsistency.
created_at: 2025-03-06T07:54:49Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,31 @@
+MonthlyDinnerOrders = 
path: DAX/calculating_dinner_data.txt
user: login: SDjon
body: Creating a header comment documentation for the file would be useful for readability.
created_at: 2025-03-06T07:56:59Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,49 @@
+Dropdown menus
+
+TotalWeekSelection = 
+DATATABLE(
+    "Week Name", STRING, 
+    "Week Offset", INTEGER,
+    {
+        {"Yesterday", -1},
+        {"Last Week", -7},
+        {"Two Weeks Ago", -14},
+        {"Three Weeks Ago", -21},
+        {"Four Weeks Ago", -28}
+    }
+)
+
+
+TotalDateSelection = 
+ADDCOLUMNS(
+    CALENDAR(DATE(2025,1,1), DATE(2025, 5, 31)),  
path: DAX/total_compare_selected_week.txt
user: login: SDjon
body: This is fine for our current data, but finding a way to update this regularly would be good.
created_at: 2025-03-06T08:02:52Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,49 @@
+Dropdown menus
+
+TotalWeekSelection = 
+DATATABLE(
+    "Week Name", STRING, 
+    "Week Offset", INTEGER,
+    {
+        {"Yesterday", -1},
+        {"Last Week", -7},
+        {"Two Weeks Ago", -14},
+        {"Three Weeks Ago", -21},
+        {"Four Weeks Ago", -28}
+    }
+)
+
+
+TotalDateSelection = 
+ADDCOLUMNS(
+    CALENDAR(DATE(2025,1,1), DATE(2025, 5, 31)),  
+    "Formatted Date", FORMAT([Date], "MM/DD/YYYY")
+)
+
+
+Selected Date Orders Total = 
+VAR SelectedTimeBucket = MAX(Total_Orders_Hourly_Buckets[Hour])
+VAR SelectedStart = SELECTEDVALUE(TotalDateSelection[Date]) + SelectedTimeBucket
path: DAX/total_compare_selected_week.txt
user: login: SDjon
body: This does not account for if the value is empty, then the return value would return something that can't be calculated. A default in case of this would be good.
created_at: 2025-03-06T08:08:12Z
author_association: CONTRIBUTOR

PR comments:
user: login: estebanrodriguez28
created_at: 2025-03-06T07:15:53Z
body: ![](https://github.trello.services/images/mini-trello-icon.png) [#3.1 Task: Create Dinner Dashboard as a report in PowerBI](https://trello.com/c/uj5eEo4V/38-31-task-create-dinner-dashboard-as-a-report-in-powerbi)
author_association: CONTRIBUTOR
user: login: estebanrodriguez28
created_at: 2025-03-06T07:17:53Z
body: ![](https://github.trello.services/images/mini-trello-icon.png) [#3.7 Task: Add ability to select a day then compare it to the orders a week ago or longer for breakfast, lunch, dinner](https://trello.com/c/r92BeZB6/47-37-task-add-ability-to-select-a-day-then-compare-it-to-the-orders-a-week-ago-or-longer-for-breakfast-lunch-dinner)
author_association: CONTRIBUTOR