Produce a Report of my undaplicated list of items

Hi all, I am new to Appsheet and straggling days about producing a report from the table below:

image

I need to write to my Report template a table containing only the unduplicated list of items in column [Name] and in the second column the SUM of the amount of each item in the column [amount], like this:

image

The best I managed to do is this: <<SORT(Unique(SELECT(Items[Name],true)))>>

But it produces one list which is not what I need: Item-1, Item-2

This can be done using other languages, such as jave, javescript, etc , so easy, but I am really finding it so hard here , can you, please, help me

<<SORT(SELECT(Items[Name],TRUE,TRUE),TRUE)>>
<<SUM(SELECT(Items[Amount],[Name]=[_THISROW].[Name]))>>
2 Likes

Your first table is a child table and the second table is the parent table. In your parent table, the column TOTAL AMOUNT should be a virtual column with the formula sum(Reference table Id, Amount)

1 Like

Hi Leventk, thanks for your response, however it raises an Error:

Operation: Workflow action

Message: Error: Report ‘MyReport’ action ‘Action 1’ Attachment template. Expression ‘SUM(SELECT(Items[amount],[Name]=[_THISROW].[Name]))’ is invalid due to: Error in expression ‘[_THISROW].[Name]’ : Unable to find column ‘_THISROW’.

Hi Servatec, thanks for your reply,
I just might need to clarify, that i just have one table which is the first table, and i need to print to my report something like second table, so i do not have two tables at all , just the first table

@khalee
Do you have only Item-1 and Item-2 in the table, or you have more Item-# records?

Hi @LeventK ,
Actually, I have lots of other items in this table Slice (Items), and everyday this table slice will auomatically contain new items of this particular day, so i need to print into my report the undaplicated items and the som amount of each one next to it ,

@khalee
Are you using Google Spreadsheet as a back-end?

i use Cloud SQL - MySQL as my backend

Why don’t you create a SQL view with a QUERY which will create a pivoted table around Item Name and get the sum of the amount column and then import that view to your app as a read-only table, and base the report as per that table?

2 Likes

Yes, but i do not have enough experince in doing such Pivoted Table im Mysql ! can you please, LeventK, point me out how to costruct a sql query to do so , or if there is a way to do it using only Appsheet ,

@khalee

CREATE VIEW assign_a_view_name_here (item_name)
AS SELECT item_name,
SUM (item_amount) 
FROM Your_SQL_Table_Name 
GROUP BY item_name;
2 Likes

That’s great, thank you, LeventK, so much,
Sorry, LeventK, but i still have other concern , about how to make the pivot table updated automatically each day (this can be done so easly using Slices in Appsheet) and based on my orginal Item table which looks like the one below:
image
so i need each day the pivot table contain only the items of today, is it, possible, LeventK ?

So you want to see the unique item totals as per TODAY()?

1 Like

yes. exactly @LeventK, and , i am thinking if there is any other way to achaive this by using only Appsheet, like if I create a new table (that gets its data from the main item table) which can hold only the undaplicated item names and the total amount for each in other column everyday ??

You can configure the created view to hold the Date column as well and then you can slice that SQL view directly in AppSheet or you can choose to group your SQL view by both date and item name and use that view to slice it with [Date]=TODAY() in AppSheet

CREATE VIEW your_view_name (date, item_name)
AS SELECT date, item_name
SUM (item_amount) 
FROM Your_SQL_Table_Name 
GROUP BY date, item_name;
2 Likes

Thanks, @LeventK so much for the help, it works, but i still have a problem that the sum of [item_amount] is not correct it does the sum of any particular [item_name] for the whole table ! , what i need is to have the sum of this particular item in a day !
and, as you know, slice in appsheet does not fix this problem, it has to be fixed in the sql view in the first place ! any hints ?

@khalee
Sometimes column order or the query sequence can be a pain matter in SQL. Can you try with:

CREATE VIEW your_view_name (date, item_name)
AS SELECT item_name, date
SUM (item_amount) 
FROM Your_SQL_Table_Name 
GROUP BY item_name, date;
1 Like

Hi @LeventK,
Thanks so much of all the help which opened my eyes on using View tables to solove lots of problems i am dealing with, the below SQL soloved my problem, it generates a View of only the current day, then i use it in my Appsheet and in my generated Report, it works so fine:

CREATE
ALGORITHM = UNDEFINED
DEFINER = workbenchuser@%
SQL SECURITY DEFINER
VIEW myView AS
SELECT
Items.Name AS TypeName,
SUM(CAST(Items.amount
AS UNSIGNED)) AS amountSum
FROM
Items
WHERE
(CAST(Items.Date AS DATE) = CAST(NOW() AS DATE))
GROUP BY Items.TypeName

1 Like

Excellent work @khalee, glad to hear that you have overcome the problem. Thanks for the feedback.

1 Like